shell

How can I create a command line (unix/linux) instruction that uses variables to execute numerous commands?

I need to rearrange some content in various directories but it's a bit of a pain. In order to debug the application I'm working on (a ruby app) I need to move my gems into my gem folder one at a time (long story; nutshell: one is broken and I can't figure out which one). So I need to do something like: sudo mv backup/gem/foo gem/ sudo ...

What does $$ mean in the bash shell?

I once read that one way to obtain a unique filename in bash for temp files was to use a double dollar sign ($$). This does produce a number that varies from time to time... but if you call it repeatedly, it returns the same number. (The solution is to just use the time.) I am curious to know what $$ actually is, and why it would be ...

design patterns or best practices for shell scripts

Does anyone know of any resources that talk about best practices or design patterns for shell scripts (sh, bash etc...)? ...

How to autocomplete at the Korn shell command line with the vi editor

In the Korn shell on AIX UNIX Version 5.3 with the editor mode set to vi using: set -o vi What are the key-strokes at the shell command line to autocomplete a file or directory name ? ...

How to suppress Terminated message after killing in bash?

How can you suppress the 'Terminated' message that comes up after you kill a process in a bash script? I tried set +bm, but that doesn't work. I know another solution involves calling 'exec 2> /dev/null', but is that reliable? How do I reset it back so that I can continue to see stderr? Thanks ...

is Microsoft sort.exe able to sort unicode UTF-16 (LE) files?

Is Microsoft sort.exe 5.1.2600.0 (xpclient.010817-1148) able to sort UTF-16 (LE) files? ...

Samba, other non interactive accounts - noshell, nologin, or blank?

Conducting a user account cleanup accross Solaris and Redhat linux systems, many of which have a number of Samba shares. What preference do people have for creating the local unix accounts for non interactive Samba users? In particular, the shell entry: noshell nologin blank And why? JB ...

sudo echo "something" >> /etc/privilegedFile doesn't work... is there an alternative?

This is a pretty simple question, at least it seems like it should be, about sudo permissions in linux. There are a lot of times when I just want to append something to /etc/hosts or a similar file but end up not being able to because both > and >> are not allowed, even with root. Is there someway to make this work without having to su...

Can anyone recommend a good modern alternative to bash?

Bash is getting a little long-in-the-tooth. Windows has PowerShell (formerly known as Monad), which is capable of dealing with richer objects than just lines of text. Is there any equivalent new powerful shell for Linux/Mac? It should be of similar expressiveness and functionality to Bash, but not afraid to tackle things in a differ...

Setting Environment Variables for Mercurial Hook

I am trying to call a shell script that sets a bunch of environment variables on our server from a mercurial hook. The shell script gets called fine when a new changegroup comes in, but the environment variables aren't carrying over past the call to the shell script. My hgrc file on the respository looks like this: [hooks] changegroup...

In a bash script, how do I sanitize user input?

I'm looking for the best way to take a simple input: echo -n "Enter a string here: " read -e STRING and clean it up by removing non-alphanumeric characters, lower(case), and replacing spaces with underscores. Does order matter? Is tr the best / only way to go about this? ...

Exit Shell Script Based on Process Exit Code

I have a shell script that executes a number of commands, and if any of the commands exit with a non-zero exit code the shell script should exit. ...

How to match a single quote in sed

How to match a single quote in sed if the expression is enclosed in single quotes: sed -e '...' For example need to match this text: 'foo' ...

Use grep to find content in files and move them if they match

I'm using grep to generate a list of files I need to move: grep -L -r 'Subject: \[SPAM\]' . How can I pass this list to the mv command and move the files somewhere else? ...

What is the linux equivalent to DOS pause?

I have a bash shell script in which I would like to pause execution until the user presses a key. In DOS, this is easily accomplished with the "pause" command. Is there a linux equivalent I can use in my script? ...

How to protect yourself against shell DLLs loaded into your process?

When you use a standard Windows "file open" dialog using GetOpenFileName(), the shell will load various DLLs that it requires to display the file list, including custom ones. In my application, I found that the DLL that TortoiseCVS uses to draw overlays on the icons was calling GdiPlusShutdown(), and so some time after displaying a "fil...

How can I tell that a directory is really a recycle bin?

I need a function that, given a path, tells me whether it is a Recycle Bin folder. I tried using functions like SHGetSpecialFolderPath with CSIDL_BITBUCKET, but that doesn't work because the Recycle Bin is a virtual folder that is the union of the Recycle Bins of all drives. This question is to document a response posted in http://blo...

Korn Shell code to send attachments with mailx and uuencode?

I need to attach a file with mailx but at the moment I'm not having a lot of success. Here's my code: subject="Something happened" to="[email protected]" body="Attachment Test" attachment=/path/to/somefile.csv uuencode $attachment | mailx -s "$subject" "$to" << EOF The message is ready to be sent with the following file or link a...

How do you run a script on login in *nix?

I know I once know how to do this but... how do you run a script (bash is OK) on login in unix? ...

How to load a python module into a fresh interactive shell in Komodo?

When using PyWin I can easily load a python file into a fresh interactive shell and I find this quite handy for prototyping and other exploratory tasks. I would like to use Komodo as my python editor, but I haven't found a replacement for PyWin's ability to restart the shell and reload the current module. How can I do this in Komodo? ...