bash

Showing only the substrings of COMPREPLY bash completion options to the user

In a bash completion script, suppose COMPREPLY=(aa/ba/ aa/bb/). When the script is invoked, the completion options looks like this to the user: $ foo aa/b<TAB> aa/ba/ aa/bb/ However, I want to have a bit more control over how these options are displayed. In particular, I want to show only a substring of each COMPREPLY option to the us...

Run bash script in PHP results in syntax error

I can use the following bash script to start severals terminals at once: for i in 0 1 2 3; do urxvt -name Terminal$i&; done But if I try to run that bash script from a PHP script if fails with error: sh: -c: line 0: syntax error near unexpected token `;' sh: -c: line 0: `for i in 0 1 2 3; do urxvt -name Terminal$i&; done' PHP Scri...

Ternary operator in Bash

Is there a way to do something like this using Bash? int a = (b == 5) ? c : d; Thanks. ...

Parsing a file of values in order to change into an SQL insert

Hey, trying to figure out a way to use a file I have to generate an SQL insert to a database. The file has many entries of the form: 100090 100090 bill smith 1998 That is,an id number, another id(not always the same), a full name and a year. These are all separated by a space. Basically what i want to to is be able to get variables f...

ubuntu/linux bash: traverse directory and subdirectories to work with files

let me start off with what I need; the program is given a directory, it will then examine all the files in the directory (works) and do stuff to the files (waiting till it can find all the files for this part). then it will look for subdirectories and re-run its self for each subdirectory. the directory I'm testing with looks like this:...

Ensuring shell script is being executed by BASH (not csh, ksh, sh etc.)

How would you exit-gracefully-upon-entry when invoking a .sh script from anything other than bash? Of course bash-isms like the following don't work in csh and the like so you get an error rather than the intended error message: if [ ${BASH_VERSION-not_running_within_bash} = not_running_within_bash ]; then ...

How to pass variable arguments from bash script to python script

Hi All... I've been trying to solve this issue for sometime now with no luck. The crust of the situation is that I'm using a bash script to send parameters to a a python script: Example: foo.sh calls bar.py....the call looks like: bar.py $var1 $var2 ... $varn The python script then prints all the arguments using the sys.argv array. T...

help with bash script

i have a homework: The student should write a bash program named fix-permissions.sh that accepts a list of users as argument If a user or more are given as arguments, the script should reset files permissions as follows.... "accepts a list of users as argument" can someone explain it to me please? ...

Error in bash script

I created a small script to start openvpn but when I try to execute it i get the following error message and i don't know what i did wrong as i'm not that good with this language: /etc/init.d/ovpn start Options error: Unrecognized option or missing parameter(s) in [CMD-LINE]:1: cd (2.1.0) Use --help for more information. Here's my cod...

Help with executing bash script from PHP

I am using Apache with PHP to execute a bash script and am running into a problem. Pseudo code... Website Button -> Click -> jQuery.post("file.php") -> php: system("/home/user/file.sh cmd") -> bash: screen -S name -> bash: java -jar file.jar The bash script then starts a named screen session, and runs a Java application (java -jar fi...

Terminal - Delete All Folders Not Conatining .mp3 Files

Hi, I'm using Banshee on Linux and I have it auto-organize my music collection in folder hierarchies. When I add a new album to my Music folder, Banshee automatically moves (and renames) the mp3s and puts them into the correct Artist folder. If there is no other file in the folder, then the folder is also deleted, but if other files are ...

print everything up to match in pattern

I have a data set that looks like the following: movie (year) genre for example. some words (1934) action My goal is to grab each "movie" field and then check a different file that also has a bunch of movies and delete the lines from the second file that do not contain the movie. I have been trying to use awk to do this, but have o...

How create a new launcher with bash shell ?

I want create a new launcher in the Application -> Game menu with bash shell. How can I do that ? ...

Bash variable assignment

In shell scripting what is the difference between these 2 when assigning one variable to another: a=$b and a="$b" and which one to use when ? ...

bash scripting with screen

I want to write a bash script that opens multiple screens and detaches them. So at the end you'll have a few screens open each running a different command. Similar to ssh: ssh DESTINATION "command 1; command 2;" my idea was to write something like this: screen -S name1 "command1" screen -S name2 "command2" ... But this doesn't wo...

Logical Error in Shell script.Please help (UNIX)

Following is a source code which takes in only 'files',lists the file permissions of a file and prints the output by replacing r=READ,w-WRITE,x-EXECUTABLE. It should also echo "User".But the My problem here is that I have replaced '-' by User but then if the file has a permission of r--x,it also prints "User" @ that point.I know its n...

How do these stream redirections work?

From this perldoc page, To capture a command's STDERR and STDOUT together: $output = `cmd 2> To capture a command's STDOUT but discard its STDERR: $output = `cmd 2>/dev/null`; To capture a command's STDERR but discard its STDOUT (ordering is important here): $output = `cmd 2> To exchange a command's STDOUT and STDERR in order to ...

Difficulty executing shell script with directory reference

Hey Guys, I have a simple script ... dir=`pwd` echo $dir cd ./selenium-grid-1.0.8/ CMD="ant -Dport=$1 -Dhost=$2 -DhubURL=http://172.16.1.137:4444 -Denvironment="$3"-DseleniumArgs="-firefoxProfileTemplate C:/software/rc_user_ffprofile -multiWindow" launch-remote-control" echo $CMD $CMD 2>&1 #End Whenever i run this command, i get: ...

Is it possible to build variable names from other variables in bash?

I apologise for the pretty terrible title - and the poor quality post - but what I basically want to do is this: for I in 1 2 3 4 echo $VAR$I # echo the contents of $VAR1, $VAR2, $VAR3, etc. Obviously the above does not work - it will (I think) try and echo the variable called $VAR$I Is this possible in Bash? ...

How to manually expand a special variable (ex: ~ tilde) in bash

I have a variable in my bash script whose value is something like this: ~/a/b/c Note that it is unexpanded tilde. When I do ls -lt on this variable (call it $VAR), I get no such directory. I want to let bash interpret/expand this variable without executing it. In other words, I want bash to run eval but not run the evaluated command. ...