bash

How can I have a terminal where error messages are coloured, similarly as here?

I would like to see errors in my terminal colorfully, similarly as here: http://stackoverflow.com/questions/452532/what-does-this-python-message-mean ...

Shell script for adjusting image size

Is there a way to adjust all image sizes in a directory? If I set the max size to 800x600 it will make larger ones smaller and leave smaller ones at their original size. Has anyone got a solution for that? Any help would really be appreciated! ...

Bash string difference

Hi there, I'm trying to find a way to determine the difference between two strings in my script. I could easily do this with diff or comm, but I'm not dealing with files and I'd prefer not to output them to files, do the compare and read it back. I see that comm, diff, cmp all allow to pass either two files OR a file and standard input...

What's the difference between $(...) and `...`

Hello! The question is as simple as stated in the title: What's the difference between the following two expressions? $(...) `...` For example, are the two variables test1 and test2 different? test1=$(ls) test2=`ls` ...

format bash variable for command

From my bash shell I would like to call a program n times with a different numbered parameter, which has to be in a fixed format like "%02i" One way would be: for ((i=23; i<42;i++)); do sh ../myprogram `printf "%02i\n" $i` done Is there a way to improve the printf.. part? I believe this might be a performance bottleneck with mor...

How do I determine if a directory is an NFS mount point in shellscript

I want to write a sh/bash script that can determine whether a particular directory is a mount point for an NFS filesystem. eg something like $ mkdir localdir $ mkdir remotedir $ mount host:/share ./remotedir $ classify_dirs.sh --> localdir is local --> remotedir is an NFS mount point ...

Creating indented text with bash

Hello. I want to print a list to screen in a readable way. I use a loop to go through each element and make a new list which is formatted with commas and newlines. The problem is that in the first line of the output, I want a title. E.g., I want to print something like this: List: red, green, blue, black, cars, busses, ... The p...

shell script to truncate all MySql tables

Hi, I'm looking for a Unix shell script that will truncate all tables in a schema. A similar question was already asked, but I have some additional requirements which makes none of the provided answers satisfactory: Must be a Unix shell script (i.e. no python, perl, PHP) The script must truncate the tables in an order which respects f...

Bash script to create symbolic links to shared libraries

I think this question is rather easy for you shell scripting monsters. I am looking for the most elegant and shortest way to create symbolic links to shared libraries for Unix by means of a bash shell script. What I need is starting out with a list of shared library files such as "libmythings.so.1.1, libotherthings.so.5.11", get the sy...

How would you represent EOF in bash?

Hello all, I'm trying to do something like read -d EOF stdin for word in $stdin; do stuff; done where I want to replace 'EOF' for an actual representation of the end of file character. Edit: Thanks for the answers, that was indeed what I was trying to do. I actually had a facepalm moment when I saw stdin=$(cat) lol Just for kicks...

Parallel processing from a command queue on Linux (bash, python, ruby... whatever)

I have a list/queue of 200 commands that I need to run in a shell on a Linux server. I only want to have a maximum of 10 processes running (from the queue) at once. Some processes will take a few seconds to complete, other processes will take much longer. When a process finishes I want the next command to be "popped" from the queue a...

php calling bash problem

I have this simple php script <?php echo '<pre>'; // Outputs all the result of shellcommand "ls", and returns // the last output line into $last_line. Stores the return value // of the shell command in $retval. $last_line = $output = system ("~/public_html/cgi-bin/srch.sh &> ~/public_html/errors.txt",$retval); // Printing additional i...

maildir headers problem

Hello, I have the followign bash script to update mtimes for maildir files: #!/bin/bash for i in /test/emailfile do date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i") newdate=$(date -d "$date" +'%Y%m%d%H%M.%S') touch -t "$newdate" "$i" done This script has always worked fine, with standard headers ...

Bash script: get sublist of file

Hi, I store the SQL script for a particular release in a subdirectory of 'scripts' named after the release version, e.g. ... ./scripts/1.8.3/script-1.8.3.sql ./scripts/1.8.4/script-1.8.4.sql ./scripts/1.8.4.1/script-1.8.4.1.sql ./scripts/1.8.4.2/script-1.8.4.2.sql ./scripts/1.8.4.3/script-1.8.4.3.sql ./scripts/1.9.0/script-1.9.0.sql ./...

changing maildir order

I recently asked this question and worked out that the reason a single email message is displaying out of order is not in fact because of the date, but because of the order of the messages. I would like to modify my script to make sure all messages are in the correct order, but am unsure how to do this. Is it just based on the order in w...

Extract all matching substrings in bash

Looking for a solution in bash (will be part of a larger script). Given a variable containing information of the form diff -r efb93662e8a7 -r 53784895c0f7 diff.txt --- diff.txt Fri Jan 23 14:48:30 2009 +0000 +++ b/diff.txt Fri Jan 23 14:49:58 2009 +0000 @@ -1,9 +0,0 @@ -diff -r 9741ec300459 myfile.c ---- myfile.c Thu Aug 21 18:22:17...

How to test if a given path is a mount point

Suppose do you want test if /mnt/disk is a mount point in a shell script. How do you do this? ...

Can a shell script set environment variables of the calling shell?

I'm trying to write a shell script that, when run, will set some environment variables that will stay set in the caller's shell. setenv FOO foo in csh/tcsh, or export FOO=foo in sh/bash only set it during the script's execution. I already know that source myscript will run the commands of the script rather than launching a new...

How do I do date math in a bash script on OS X Leopard?

I realize I could whip up a little C or Ruby program to do this, but I want my script to have as few dependencies as possible. Given that caveat, how does one do date math in a bash script on OS X? I've seen a post (on another site) where someone did the following: date -d "-1 day" But this does not seem to work on OS X. Addendum: S...

How can I ping many subsites ~/[0, 3].html in Bash?

Code: for i in {0..3}; do ping http://www.pythonchallenge.com/pc/def/$i.html; done A host should be found at www.pythonchallenge.com/pc/def/0.html. I get this error for all pings: ping: cannot resolve www.pythonchallenge.com/pc/def/0.html: Unknown host ...