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

learn more… | top users | synonyms

2
votes
2answers
46 views

An alias for a command to kill stopped jobs

I wanted to add an alias to my .bashrc so that I could kill all stopped jobs with a command like kill_stopped. I am aware that kill `jobs -p` can be used to accomplish this but I'd rather have an ...
9
votes
4answers
418 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
2
votes
2answers
46 views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
1
vote
1answer
34 views

How can I maintain line breaks in body text with mailx when sending attachments?

I have a script that emails the text of a log file as the body of the email. That log file has some blank lines between lines of text for readability. When I use the following line in the script, ...
2
votes
2answers
191 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
0
votes
1answer
56 views

How can I echo dollar signs?

For example, $PATH and $HOME When i type echo $PATH it returns my $PATH, but i want to echo the word $PATH and not what the actual variable stands for, echo "$PATH" doesn't work either. It might ...
5
votes
1answer
36 views

Representing/quoting NUL on the command line

Can \0 be used on the command line? Background For testing corner cases in GNU Parallel I was curious whether all characters were correctly quoted on the command line. Most of them are: perl -e ...
3
votes
1answer
117 views

How can I run a bash variable as a command exactly without additional quotation?

I'm trying to make a script which needs to save a command to be run as a string. The string in question needs to contain quotes, and when attempting to execute it bash adds additional quotation ...
2
votes
3answers
63 views

How to nest quotes in bash commands

I want to test the result of this command: dmesg | grep "Firmware patch 1563" Therefore, I try to write something like this: if [ "`dmesg | grep "Firmware patch 1563`" == "" ] But it doesn't ...
2
votes
4answers
201 views

Passing wildcard * to a (bash?) script [duplicate]

I want to to remove all color codes which look like '@n', '@R' etc, from a moderately large size collection of text files. So in a file called 'remove_cc', I wrote the following: sed -ie 's/@r//g' ...
1
vote
1answer
49 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
4
votes
2answers
173 views

How to escape single quotes correctly creating an alias

I've been given this one-liner to know how much memory my processes consume. $ ps -u $USER -o pid,rss,command | \ awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}' Now I'd like to ...
2
votes
2answers
48 views

Is there an improved version of “pick” that will work with filenames with spaces?

Is there a version of the pick script that will work properly with spaces in the filenames? This is a tricky question—pick is trivial to enhance to work with spaces in filenames, but the output ...
2
votes
3answers
102 views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i ...
2
votes
1answer
69 views

Shell command works locally but does not get parsed correctly through ssh

If I execute the following shell command locally, I get the expected result: adb -s 123456789 shell "su -c 'mount -o remount,rw /system;rm -r /system/app/MyApp.apk;cp /sdcard/MyApp.apk ...
3
votes
1answer
34 views

Why do I get an error when double quoting single quotes in a script that launches a remote SSH command?

I have this script: port=$1 cmd=$2 ssh root@127.0.0.1 -p $port "'"$cmd"'" When running myscript.sh 1000 "ls /dev/shm" it get this error: bash: ls /dev/shm: No such file or directory In the ...
5
votes
3answers
147 views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
0
votes
0answers
50 views

What is the difference between double quotes (“”) and single quotes ('')? [duplicate]

I really do not know the usage of " and '. I want to know usage of " and '. What is the difference between echo "hi" and echo 'hi'.
1
vote
2answers
44 views

When to use bash ANSI C style escape, e.g. $'\n'

I don't use bash often but I recall in the past to pass a tab or newline on the command line I would have to escape the character using the special $ character before a single quoted string. Like ...
9
votes
4answers
420 views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, ...
0
votes
0answers
24 views

Zsh - Modify File Completion w/ Quotes

I've been using Zsh recently, and when I complete a file name within quotes, the completion adds a space after the completed file name. Interestingly, this does not occur when I complete directory ...
7
votes
2answers
390 views

Bash string concatenation used to build parameter list

Given this piece of bash: PARMS='-rvu' PARMS+=" --delete --exclude='.git'" echo $PARMS rsync ${PARMS} . ${TARGET} The echo shows the PARMS string as expected, no error is displayed, but rsync ...
4
votes
1answer
126 views

Bash script for scp interpreting tilde (~) too soon

So, I just started a new C++ class that requires me to program in a Linux environment. I don't have Linux installed on my machine, but I do have OS X and I can ssh into a linux machine in the lab at ...
1
vote
1answer
64 views

Copy newest file in directory over SSH

How might one copy the newest text file from a particular directory on a remote server to his local machine? On the server itself I can do the following: $ cat `cd /home/user/dir ; readlink -f $(ls ...
2
votes
3answers
112 views

Checking if an input number is an integer

I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs ...
2
votes
1answer
79 views

How can I pass a filename containing percent signs (%) as a parameter to a shell script in cron? [duplicate]

We have currently setup a cron job for our new script as below: 46 22 * * * /gzm_common/diagbat9/global/prod/chgstatus.sh /backups/diagbat9/Demantra/output/SK_ITEM_EXTRACT_MFGPRO_$(date +%m%d%y).txt ...
2
votes
2answers
71 views

Replace a backslash with sed

I've been trying to create a script that would replace every occurence of C:\ in two different types of file by /root. My arborescence looks like : - Batch - Place of the script - Conf - Appli1 ...
0
votes
1answer
40 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
3
votes
3answers
240 views

Preventing a specific space from being expanded in a variable

In bash how do you avoid a specific space from being expanded in a variable? Lets say I have this JAVA_OPTS="-Xmx1g" JAVA_OPTS="$JAVA_OPTS -XX:OnError='/path/to/a/script.sh %p'" function args() { ...
4
votes
2answers
67 views

Inconsistent redirection behavior ssh interactive vs commands

These work, ssh remote 'echo hi > hi.txt' echo hi | ssh remote 'cat > hi.txt' but this does not work ssh remote sh -c 'echo hi > hi.txt' I expected to produce a file on remote named ...
16
votes
5answers
1k views

Parenthesis in bash arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
4
votes
1answer
638 views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
1
vote
1answer
57 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
3
votes
5answers
339 views

How to use a shell variable inside sed's s command? [duplicate]

we know that we can get the value of a variable using $ sign: x=3 echo $x 3 Is there other ways that we can use to get the value without using $ sign. I'm asking this because $ sign is a special ...
2
votes
2answers
77 views

How to escape spaces etc in passed variable, for system call to cp in awk

As the title suggests, this problem has enough layers of complexity to make simple escaping characters difficult for me. I have a bash script which, for a large part, has an embedded awk script that ...
2
votes
2answers
232 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
2
votes
0answers
125 views

How to pass multiple commands via pssh and multiple xterms

I'm attempting to open multiple xterms and run a command as an SAP user via sudo using pssh. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in the servers ...
5
votes
1answer
534 views

What does su - `whoami` command do?

I am running a script in my project and I see this command su - `whoami` I am having a few basic questions: What does this command do ? What is the significance of `` quotes outside the whoami ...
3
votes
2answers
48 views

How to build space separated, escaped full paths of files recursively matching glob?

I have a program which requires paths to files as arguments, which cannot be quoted and must not depend on working dir. Can this be done without chaining multiple xargs, tr, find, readlinks? Example ...
2
votes
1answer
99 views

Backslash with pipe in system command from awk

I want to invoke shell command from awk so I am using system() but when I am passing expression in I am getting error at backslash. Here is my expression echo "select * from abc limit 1;"| ...
5
votes
1answer
634 views

Why do I have to escape a “dot” twice?

I know that we can escape a special character like *(){}$ with \ so as to be considered literals. For example \* or \$ But in case of . I have to do it twice, like \\. otherwise it is considered ...
0
votes
2answers
76 views

Why does passing a HEREDOC as a string to `ruby -e` not work?

For reasons I don't understand, it seems to be impossible to pass a heredoc as an expression to a Ruby interpreter: $ ruby -e <<END heredoc> puts 'hi' heredoc> END ruby: no code ...
4
votes
2answers
279 views

Add arguments to bash -c

Let say that I want to run a command through bash like this: /bin/bash -c "ls -l" According to bash man page, I could also run it like this: # don't process arguments after this one ...
1
vote
1answer
58 views

How could I retain special character without replacing it with underscore?

I'm working on a file transfer script where I encounter a problem, when the file name look like Dr' A. The transfer script will fail due to following error: sftp> put /path/Dr'\ A.tif Unterminated ...
5
votes
1answer
183 views

Test -n gives unexpected result

I understand test -n <expression> to return false if the expression evaluates to a string length of greater than 0. Why then does the following happen? Macbook:~ echo ${#undeclared_variable} 0 ...
1
vote
1answer
58 views

How to enclose a quoted variable in quotes

I want to call: ./mjpg_streamer -i "./input_uvc.so -r 320x240" -o "./output_http.so -w ./www" from a C program, running system(). The problem is that I have to enclose shell command in quotes, which ...
2
votes
1answer
68 views

Could “>” be included in a bash Variable?

Current approach: sudo awk 'BEGIN{printf "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<hello>\n\t<world>\n";} {print "\t\t",$0}END{printf "\t </world>\n</hello>\n"}' ...
2
votes
1answer
74 views

Change a specific line using sed

I need to change a line in a Java file called DbConnection.java using the sed command. The line is: connection = DriverManager.getConnection("jdbc:mysql://**localhost**/**bajaj**","**root**", ...
1
vote
2answers
202 views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
3
votes
2answers
273 views

Variable assigned inside ssh command doesn't return proper value

I'm executing the below command in the ssh part of my script. The command is meant to cut the file size from ls option and storing it to a variable. Then print the variable: echo "Enter srouce file"; ...