Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.

learn more… | top users | synonyms

20
votes
2answers
757 views

Why escape trivial characters in shell script?

I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code: [ -f $myfile ] && \rm -f $myfile The escaping backslash ...
3
votes
3answers
554 views

pull out a file named to ~

So I have downloaded a music album from aMule and it is located in the .aMule/Incoming directory. I tried to move it out with the following command: mv albumName.rar ~ This left me with a file ~ ...
4
votes
1answer
223 views

Mutt: can I define my own rules for quoted message detection?

I recently started using mutt with my gmail IMAP mail address. Because I loved it so much, I also set it up with my college email address. This, sadly, is hosted by the college ICT team under ...
2
votes
2answers
432 views

Shell script output incorrectly splitting while being passed as an argument to script

Let's say I have the following two shell scripts: #!/bin/sh #This script is named: args.sh echo 1 "\"Two words\"" 3 , and: #!/bin/sh #This script is named: test.sh echo "Argument 1: "$1 echo ...
15
votes
3answers
7k views

Can't use exclamation mark (!) in bash?

I'm trying to use the curl command to access a http url with a exclamation mark (!) in its path. e.g: curl -v "http://example.org/!287s87asdjh2/somepath/someresource" the console replies with bash: ...
1
vote
3answers
1k views

How can we rename a file with semi-colon as part of the filename?

I tried to rename all file with extension "XLS;1" to "XLS" but it just didn't work. I tried the following in cygwin in windows xp and they don't work: mv *.XLS;1 *.XLS mv *.XLS\;1 *.XLS mv ...
24
votes
3answers
48k views

What characters do I need to escape when using sed in a sh script?

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
0
votes
1answer
425 views

Shell script to check server state

I am writing a script that would ssh into the VMWare server and check if the VMs are up or not. There's some error in the server=awk "/$i/{print $2}" /home/dharmit/scripts/vmids line. I am getting ...
7
votes
2answers
2k views

Number of backslashes needed for escaping regex backslash on the command-line

I recently had trouble with some regex on the command-line, and found that for matching a backslash, different numbers of characters can be used. This number depends on the quoting used for the regex ...
27
votes
3answers
6k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
3
votes
1answer
7k views

grep and escaping a dollar sign

I want to know which files have the string $Id$. grep \$Id\$ my_dir/mylist_of_files returns 0 occurrences. I discovered that I have to use grep \$Id$ my_dir/mylist_of_files Then I see that the ...
1
vote
2answers
858 views

Issue with mv command in a script

This must be a very simple issue to solve, but I am stuck (not a UNIX pro). I need to move a gz to a target directory, but I get a No such file or directory. NOW=$(date +"%Y-%m-%d-%T") ...
4
votes
1answer
617 views

Calling script from bash has problem with arguments

I have a script that generates an xml file and then executes a perl script, passing a series of arguments to it. Here's the key code: CMD="./dnscurl.pl --keyname $KEYNAME -- -X POST -H ...
21
votes
1answer
4k views

How can I execute `date` inside of a cron tab job?

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
2
votes
3answers
300 views

man xargs says standard input is delimited by blanks; but is it?

I'm puzzled by what actually defines an arg in xargs. The man page seems to suggest that args are delimited by blanks (I assume that means whitespace). However the following script doesn't behave as ...
5
votes
1answer
5k views

Bash: Merge foldername from variable with filename

First I write a configfile with all my parameters like this path="/home/test/" I name it test.conf. Then I write a shell script with this content, name it test, and make it executable with chmod ...
1
vote
1answer
561 views

Execute command through SSH

I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra ...
3
votes
3answers
549 views

Escaping argument in bash script?

I'm writing a bash script wherein I want to check that one of the arguments passed to it is a valid group. I have the line if [ `grep -c -e '\b$2\b' /etc/group` -eq 0 ]; then echo "Error: $2 is ...
15
votes
3answers
23k views

What does ` (backquote/backtick) mean in bash?

I came across the following command sudo chown `id -u` /somedir And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does ...
10
votes
2answers
6k views

How are parenthesis interpreted at the command line?

While reading up on how to set up grub, one article mentioned that I need to use a syntax like echo \(hd0,0\) >> /boot/grub/grub.conf or echo '(hd0,0)' >> /boot/grub/grub.conf ...
2
votes
2answers
751 views

How do I echo a command and include line returns?

I am writing a bash script, and on a condition I'd like to output ps aux --sort -rss However, when I write : echo `ps aux --sort -rss` everything is on one huge line. How do I run it so it outputs ...
3
votes
1answer
166 views

Why does this variable have no value even though it is set in .bashrc?

If I append this: hi=11 export hi to the .bashrc and then I su to this user with: su - bela then I: echo $hi 11 Then it's working, the "hi" variable has the value of "11". But. When I: ...
4
votes
4answers
10k views

Why is echo ignoring my quote characters?

The echo command isn't including the complete text that I give it. For example, if I do: $ echo ' echo PARAM=` grep $ARG /var/tmp/setfile | awk '{print $2}' ` ' It outputs: echo PARAM=` ...
4
votes
1answer
2k views

sudo -u username -s “cmd arg” returns command not found

I used to execute the command: sudo -u elasticsearch -s "ulimit -Hn" and it was returning the value of ulimit -Hn as seen by user elasticsearch until I tried it on Ubuntu 11.10. There it returns: ...
5
votes
1answer
2k views

Wrapping a command that includes single and double quotes for another command

I recently learned about watch, but am having trouble making it work with relatively sophisticated commands. For example, I would like to ask watch to run the following command on zsh every three ...
3
votes
2answers
2k views

Ignore escape characters when printing string in shell script

I just wrote a simple shell script to save a LaTeX expression as a PNG file. It works fine, except for the LaTeX-syntax for "next row", i.e. the double backslash \\. When for instance my input ...
4
votes
2answers
261 views

Understanding quotes in a bash conditional instruction

My friend is messing around with Bash scripts and he wanted me to take a look at them (he had another friend do it for him). One of the commands is if [ "`pidof transmmission-gtk`"=0 ]; what ...
4
votes
1answer
88 views

Quoting in a function results in error

How should I write the command variable to get the expected behavior? #!/bin/bash function f ( ) { echo "$2" } command="f --option=\"One Two Three\" --another_option=\"Four Five Six\"" $command ...
21
votes
7answers
15k views

How to add newlines into variables in bash script

When I do str="Hello World\n===========\n" I get the \n printed out too. How can I have newlines then?
2
votes
3answers
145 views

How to pass lines from a file to a bash script, so that each line remains undivided, even if there are spaces?

Given: $ cat lines.txt a/b 'c/d e/f' $ cat 1.sh #!/bin/sh ./2.sh `cat lines.txt` $ cat 2.sh #!/bin/sh echo p1=$1 echo p2=$2 echo p3=$3 $ ./1.sh p1=a/b p2='c/d p3=e/f' How do I change lines.txt ...
2
votes
3answers
486 views

variable concatenation not working?

I have a simple bash shell script which is driving me bonkers. All I want to do is run a command which returns a result which I will then use in another command. The result of the first command ...
4
votes
2answers
4k views

Why does the exclamation mark `!` sometimes upset bash?

I realize that ! has special significance on the commandline in the context of the commandline history, but aside from that, in a runing script the exclamation mark can sometimes cause a parsing ...
2
votes
2answers
2k views

Bash color output fails

Is it sed or echo problem? What I'm doing wrong? $> cat ~/bin/color_test.sh #!/bin/bash ColorOff='\e[0m' # Text Reset BWhite='\e[1;37m' # Bold White string="test TEST test" echo -e ...
2
votes
2answers
298 views

Bash Script Argument Regex Group Conflict

I have a simple bash script: input_dir="`dirname $1`/`basename $1`/" output_dir="`dirname $2`/`basename $2`/" ext=$3 ... ... ... echo -n `rename "-f" "'s/.*([0-9]{11}_[0-9]{11}).*\.(.*$)/$1.$2/'" ...
4
votes
2answers
2k views

How to escape < or > in a parameter in shell?

I'd like to use grep with a PCRE expression that contains the < character. Bash thinks I want to redirect, but I don't want to. How can I escape <?
9
votes
2answers
4k views

What is the significance of single and double quotes in environment variables?

I defined some environment variables in my .profile like this: MY_HOME="/home/my_user" but the variable does not seem to evaluate unless I strip off the quotes and re-source the file. I believe ...
2
votes
2answers
440 views

Run ssh as a command of another ssh command

I want to run a program on a machine that I have ssh access to from a gateway machine that I can access with ssh too. When I want to run an mpi program on the target machine T, I access to the ...
0
votes
3answers
1k views

Why can't I run this script?

$ sh bashtrrrrrr # whats my pub. ip? bashtrrrrrr: line 19: unexpected EOF while looking for matching `'' bashtrrrrrr: line 20: szintaktikai hiba: váratlan fájl vég $ cat bashtrrrrrr #!/bin/bash ...
5
votes
2answers
334 views

Bash, curious about echo $variable

I was hacking at a small script earlier and noticed something I can't explain. Running this command (time wget --spider http://www.google.co.uk/) 2>&1 | egrep 'real|response' gives me ...
5
votes
1answer
3k views

Dollar sign interpolation inside quotes in bash

I am running this little test script I wrote : #!/bin/bash TESTCASE=$@ testHarness <<runTest $TESTCASE runTest from the command line : ./test.sh "1092$212" but the dollar sign is being ...
2
votes
2answers
377 views

bash quotes expansion puzzle

My script looks like: opts="-x ''" curl http://somepage $opts I want the string in $opts appended to the command. I use bash -x test.sh to check the expansion and see that the the single-quotes are ...
5
votes
3answers
4k views

Why the double quotes and backquotes in a shell script?

I'm looking at this script mysql backup script and I don't understand what is the reason for using both backticks and double quotes around command names? 379 WHICH="`which which`" 380 AWK="`${WHICH} ...
1
vote
2answers
2k views

Creating an empty file having a variable name in a script

I need to create an empty file using a shell script. The filename will be determined by examining all the files in a directory matching a pattern, say TEST.*, and appending _END to it so that the new ...
14
votes
2answers
941 views

gnu find and masking the {} for some shells - which?

The man page for gnu find states: -exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, ...
4
votes
2answers
2k views

Escaping quotes in zsh alias

Following on from this question about stripping newlines out of text, I want to turn this into a zsh alias as follows: alias striplines=' awk " /^$/ {print \"\n\"; } /./ {printf( \" %s \",$0);}"' ...
3
votes
1answer
402 views

Difference between ' and " on command line (bash)?

I used to use '' and "" interchangeably on the command line, but I recently noticed that '$HOME/some/dir' is not expanded, while "$HOME/some/dir" is. I searched around a little bit and found that "" ...
9
votes
3answers
4k views

How to properly escape exclamation points in bash?

Today, I was caught redhanded while attempting to code golf a password generator for Twitter. import string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9)) 90 chars. ...
38
votes
2answers
3k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
21
votes
4answers
7k views

Quoting in ssh $host $FOO and ssh $host “sudo su user -c $FOO” type constructs

I often end up issuing complex commands over ssh; these commands involve piping to awk or perl one-lines, and as a result contain single quotes and $'s. I have neither been able to figure out a hard ...
4
votes
1answer
1k views

Read space as input in shell script [duplicate]

How can I give space " " as input in shell script ? Ex : echo " Enter date for grep... Ex: Oct 6 [***Double space is important for single date***] (or) Oct 12 " read mdate echo $mdate I get the ...