bash

How can I compare a number against a range in bash or Perl?

How to script a comparison of a number against a range? 1 is not within 2-5 or 3 is within 2-5 ...

Problems using git diff to create file list for deploy

I want to use something like the following command to create a tarball to deploy: tar cjvf ~/deploy.tar.bz2 `git diff --name-only 0abc 1def` The inner git diff command produces a list of files with relative including the relative path when i run it separately. I'm running into two problems though, I need to be able to auto escape sp...

Perform a command when a process dies

Hi, I want to execute a command when a process dies. I have a solution already, but I'm looking to see if there is a nicer way to do this as a way of further learning BASH. Here is what I have: $ ps -e | grep scp 7673 pts/1 00:01:17 scp $ while [ $( ps 7673 2>&1 >/dev/null; echo $? ) = 0 ]; do sleep 1; done; echo "Scp doesn't exist...

Batch Renaming with Bash

How can Bash rename a series of packages to remove their version numbers? I've been toying around with both expr and %%, to no avail. Examples: Xft2-2.1.13.pkg becomes Xft2.pkg jasper-1.900.1.pkg becomes jasper.pkg xorg-libXrandr-1.2.3.pkg becomes xorg-libXrandr.pkg ...

how do you echo a 4 digit unicode character in bash

I'd like to add the Unicode skull and crossbones to my shell prompt (specifically the 'SKULL AND CROSSBONES' (U+2620)) but I can't figure out the magic incantation to make echo spit it, or any other, 4 digit Unicode character. 2 digit one's are easy echo -e "\x55", for example. In addition to the answers below it should be noted that, o...

Print a file skipping X lines in Bash

Hi I have a very long file which I want to print but skipping the first 1e6 lines for example. I look into the cat man page but I did not see nay option to do this. I am looking for a command to do this or a simple bash program. I know how to do it using a program in C but I want to do it using the common commands. Any way to do it? Tha...

sort | uniq | xargs grep ... where lines contain spaces

I have a comma delimited file "myfile.csv" where the 5th column is a date/time stamp. (mm/dd/yyyy hh:mm). I need to list all the rows that contain duplicate dates (there are lots) I'm using a bash shell via cygwin for WinXP $ cut -d, -f 5 myfile.csv | sort | uniq -d correctly returns a list of the duplicate dates 01/01/2005 00:22 01...

Capturing multiple line output to a bash variable

I've got a script 'myscript' that contains the following: abc def ghi in another script, I call: declare RESULT=$(./myscript) and $RESULT gets the value abc def ghi Is there a way to store the result either with the newlines, or with '\n' character so I can output it with 'echo -e'? ...

Linux: Removing files that don't contain all the words specified

Inside a directory, how can I delete files that lack any of the words specified, so that only files that contain ALL the words are left? I tried to write a simple bash shell script using grep and rm commands, but I got lost. I am totally new to Linux, any help would be appreciated ...

bash : how to use screen to have a term session used at home after work?

Everything is in the title, I would like to start a session at work and be able to get it when i'm at home. ...

How can I cut(1) camelcase words?

Is there an easy way in Bash to split a camelcased word into its constituent words? For example, I want to split aCertainCamelCasedWord into 'a Certain Camel Cased Word' and be able to select those fields that interest me. This is trivially done with cut(1) when the word separator is the underscore, but how can I do this when the word i...

Upgrading Python on OS X 10.4.11

I downloaded a package installer for Python 2.6.1, but when I use the python command in terminal (bash) Apple's shipped 2.3.5 version loads up. How can I get 2.6.1 to load up instead? ...

With Bash Scripting, how can I suppress all output from a command?

I have a bash script that runs a program with parameters. That program outputs some status (doing this, doing that...). There is no option for this program to be quiet. How can I prevent the script from displaying anything? I am looking for something like windows "echo off". ...

How do I make this python command line an alias in bash?

I want a quick an easy way to check my ip address after reading a recent question that had been answered on SO. For future reference, is there a way to make the following alias work? alias myip='python -c "from urllib import urlopen; print urlopen("http://whatismyip.appjet.net").read()[:-1]"' ...

Select unique or distinct values from a list in UNIX shell script

I have a ksh script that returns a long list of values, newline separated, and I want to see only the unique/distinct values. It is possible to do this? For example, say my output is file suffixes in a directory: tar gz java gz java tar class class I want to see a list like: tar gz java class ...

Using the read command to parse du -s output in linux shell script

I'm trying to write a shell script to perform actions if a users home directory if over a certain size. Unfortionately when I try to use the read command to split up the du -s output I get 'command not found' since it tries to pass the number through to the shell, not into a variable like I want. Here's what I have so far for the script....

Providing Documentation for an Unix command?

I made an Unix command called macmac2unix, which converts a Word file from Mac to Unix. How can I provide documentation for my command? I want to read about my command with man $man macmac2unix ...

Executing own Unix command in terminal?

I made an Unix command, macmac2unix, which converts Mac's Word file for Unix platforms. I would like to run the command as $macmac2unix file1 file2 file3 ... Problem: How can I run this command in every path? I added the following to .bashrc unsuccessfully CDPATH=:/Users/Sam/Documents/Unix ...

Problem with Bash's command_not_found_handle()

I get "command not found" error in Mac by the following command md5sum *.java | uniq -d -w32 The reason is that Mac does not have -w option by default. I would like to make Bash to do the following when the error occurs put g at the beginning of the first command put g at the beginning of a command which is after | How can you ma...

For Loop in Shell Script - add breakline in csv file

Hello all, I wish to introduce a for loop in my shell script and I was hoping I could get some help with this. I am executing a command from a text file. I wish to execute each command 10 times and insert some stats into a csv file. After that command has been done, I want to start the next BUT put a line break in the CSV file after th...