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

learn more… | top users | synonyms

4
votes
2answers
270 views

Why am I observing different behaviour of echo?

I am a bash beginner and observed the below behavior of echo #!/bin/bash x=" hello" echo $x echo "$x" Now when I run the above code I get ronnie@ronnie:~$ bash test.sh hello hello ...
0
votes
2answers
142 views

sqlite fts quoting problem

I can do this in sqlite tool: sqlite> select caption from notes_fts where notes_fts MATCH '"perl install"'; but cannot from the Linux shell i.e., this fails: user@host:~$ sqlite3 sqldb ...
1
vote
4answers
167 views

Syntax error in a bash script that calls find

Where is the error in this script please: #!/bin/bash rep="git" files=`find' ${rep} '-type f` for f in ${files} do echo $f done When i run find git -type f alone in the shell, it works!
3
votes
2answers
336 views

how to grep for c:\

I'm using cygwin's grep to find all instances of hardcoded paths on c drive. doing: grep -r "c:\\" . gives grep: trailing backslash Does anybody know how I can do this?
2
votes
3answers
462 views

Is there a way to get *actual* (uninterpreted) shell arguments in a function or script?

I have a function posix that I use in the Git bash shell on Windows to transform DOS-style paths to normal Unix-style paths. Since DOS-style paths use a backslash as separator, I have to quote the ...
0
votes
1answer
204 views

How to run svn when ssh over ssh?

I need to run sudo -u wwwrun sh -c 'svn status -uq /srv/www/htdocs/loquat' over ssh. When using one ssh it works smoothly. Now there is one server that needs to be connected through another server via ...
3
votes
1answer
199 views

Bash script with quotes and spaces

I'm trying to get some nice output out of git: FORMAT='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' LOG_PARAMS="--color --pretty=format:$FORMAT --abbrev-commit ...
1
vote
1answer
75 views

Apostrophe appearing as space

I am trying to insert the following message: friend's mobile number from a file over redhat server into sql server 2005. this message is appearing in the sql server as below: friend s mobile ...
1
vote
2answers
151 views

run bash in script

I want to creat a script to run an another script with a several parameter exp=([1]=bloc [2]=ins [3]=rep [4]=op) for j in ${!exp[*]} do arr=([1]=mem [2]=gen [3]=usr) for i in ${!arr[*]} ...
15
votes
3answers
4k views

What does it mean to have a $“dollarsign-prefixed string” in a script?

I just saw this in an init script: echo $"Stopping Apache" What is that dollar-sign for? My research so far: I found this in the bash manual: extquote If set, $'string' and ...
3
votes
4answers
319 views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
2
votes
1answer
293 views

Command substitution: file or command not found

The following script #!/bin/bash QUERY='select * from cdr;' MYROWS=$("sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db '${QUERY}'") gives me ./bla.sh: row 35: sqlite3 -list ...
4
votes
2answers
2k views

Passing arguments with quotes and doublequotes to bash script

At this moment I have: #!/bin/bash screen -p 'ScreenName' -x eval 'stuff '"'"$@"'"'\015' echo eval 'stuff '"'"$@"'"'\015' But when I call my script as: # script.sh asd "asd" 'asd' my arguments ...
3
votes
1answer
341 views

Is it a bug for join with -t\t?

I have a problem with the command join. "The default join field is the first, delimited by whitespace" (Cited from join --help). However, there is a field containing sentences in my tab-delimted ...
1
vote
5answers
3k views

bash execute read command from file

After some manipulations, I got the file with commands that I would be glad to be able to execute. Input file (name of file is inp2.txt): "02 - Beautiful Emptiness.mp3" "02 - Come. mp3" "02 - Go ...
-1
votes
1answer
1k views

How to move file from one folder to another in shell script by changing the permission

I want to move a file from one folder to another folder. When the file's format is with space in between (file _name.dat) and when I am using the command mv file _name.dat /tmp then the file is not ...
1
vote
4answers
1k views

Appending a string containing escape character with sed

Currently I use: sed -i -e "5a\\ ${text}" $filename to append something to a certain line, where the variable text contains a string such as "\epsilon". When using echo -E $text the string is ...
4
votes
1answer
550 views

How to run this in sudo?

I have this line that I execute from php sudo -u db2inst1 -s -- "/opt/ibm/db2/current/bin/db2 connect to PLC; /opt/ibm/db2/current/bin/db2 \"update EDU.contact set MOBILE_PHONE = '123'\"" it works ...
2
votes
2answers
2k views

Change directory with space followed by '('

There are two directories I can change to: Program Files/ Program Files (x86)/ I can change to first one by writing: cd Program\ Files But the second for second one: cd Program\ Files\ ...
1
vote
2answers
458 views

Weird zsh grep -P behaviour

I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is ...
3
votes
3answers
3k views

Why does bash variable expansion retain quotes?

> echo "hi" hi > VAR='echo "hi"' > $VAR "hi" Why is the output of the above commands different? A similar thing occurs with single quotes: > VAR="echo 'hi'" > $VAR > 'hi'
1
vote
1answer
448 views

Escape text for further passing to zenity

I am going to show an error window using zenity: /usr/bin/zenity --error --text="my error message" The error text to pass is obtained as output from another application. This output may contain ...
5
votes
1answer
145 views

find usage - command line vs script

I am seeing different results from the find command between being run manually on the command line vs run in a script. If I run the following on the command line: find . -name '*.txt' ! -name ...
3
votes
2answers
273 views

issues with GNU tail -f and combination of commands

$ tail -f /logs/filename.log | awk '!(/list)' I am able to run this command in GNU Linux flavour But when I written in a script it is not working. test.ksh: variable="/logs/filename.log | awk ...
21
votes
4answers
39k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
4
votes
1answer
226 views

printing a string's “canonical print-escaped form”

I'm trying to write a function, I'll call it escape, that will behave like this: % IFS=$' \t\n\000' % escape FOO $IFS FOO=$' \t\n\000' In other words, escape takes two arguments, and then, taking ...
20
votes
2answers
720 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
476 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
201 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
347 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 ...
14
votes
3answers
5k 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 ...
15
votes
3answers
27k 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
365 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 ...
5
votes
2answers
1k 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 ...
26
votes
3answers
4k 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
4k 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
693 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
503 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 ...
13
votes
1answer
3k 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 ...
1
vote
3answers
259 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 ...
4
votes
1answer
3k 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
486 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
431 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 ...
10
votes
3answers
15k 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 ...
8
votes
2answers
3k 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
521 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 ...
2
votes
1answer
156 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
5k 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: ...