sh

How can I tell from a within a shell script if the shell that invoked it is an interactive shell?

I'm trying to set up a shell script that will start a screen session (or rejoin an existing one) only if it is invoked from an interactive shell. The solution I have seen is to check if $- contains the letter "i": #!/bin/sh -e echo "Testing interactivity..." echo 'Current value of $- = '"$-" if [ `echo \$- | grep -qs i` ]; then echo ...

perl backticks: use bash instead of sh

Hi, I noticed that when I use backticks in perl the commands are executed using sh, not bash, giving me some problems. How can I change that behavior so perl will use bash? PS. The command that I'm trying to run is: paste filename <(cut -d \" \" -f 2 filename2 | grep -v mean) >> filename3 ...

Bash scripting, zip update question: Deleting removed files from archive

I am rsync'ing a a folder from one host to another, I am then zipping the mirrored folder so that it can be transferred to tape. Now, when I zip the folder (bearing in mind that the folder is ~300GB) using the below script it keeps the files which have been deleted from the directory that I am zipping. zip -ru /home/rsync/www.zip /home...

Bash: append text to last line of file

How can I add a percentage symbol % to the end of the last line in a text file? I do not want the % to be on a new line, it must be at the end of the last line. Thanks! ...

I need to backup and then recover multiple files in different directorys with /bin/sh

As the title say. I need to be able to backup and then recover files. To make the back up was pretty simple if [ "$bup" = "true" ]; then cp $file $file.bak But to make the recovery.. was not as stright forward. elif [ "$rup" = "true" ]; then bak=`find /path/to/file/ | grep .bak` cp $bak ${bak/\.bak} fi It works i...

RegEx in bash-script (for-loop)

I want to parse the arguments given to a shell script by using a for-loop. Now, assuming I have 3 arguments, something like for i in $1 $2 $3 should do the job, but I cannot predict the number of arguments, so I wanted use an RegEx for the range and $# as the number of the last argument. I don't know how to use these RegEx' in a for-loop...

question about command substitution and bashism

there are two different syntaxes for command substitution FOO=$(echo bar) and FOO=`echo bar` as far as i know, the first method is defined in bash, while the second is defined in sh. consider the following use of command substitution in an sh script #!/bin/sh FOO=$(echo bar) does that fall under the definition of bashism? b...

Why does bash in posix mode fail to chase my symlinks?

I'm seeing weird behavior when I run "ssh " to a Linux system. I tracked it down part way to a difference in bash when started in posix mode. % bash --posix % ln -s /tmp mytmp % cd mytmp % pwd /home/user/mytmp The bash man page has these items under posix mode: --> When the cd builtin is invoked in logical mode, and the pathname con...

Linux: Run a binary in a script

Hi all, i want to run a program via script. normally i type ./program in the shell and the program starts. my script looks like this: #!/bin/sh cd /home/user/path_to_the_program/ sh program it fails, i think the last line went wrong... i know this is childish question but thx a lot! ...

Is there a way to prevent sh/bash from performing command substitution?

From a C program I want to call a shell script with a filename as a parameter. Users can control the filename. The C is something like (initialization/error checking omitted): sprintf(buf, "/bin/sh script.sh \"%s\"", filename); system(buf); The target device is actually an embedded system so I don't need to worry about malicious use...