Skip to main content

Questions tagged [quoting]

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

4 votes
1 answer
725 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 ...
ДМИТРИЙ МАЛИКОВ's user avatar
127 votes
9 answers
233k 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?
Jiew Meng's user avatar
  • 2,453
2 votes
3 answers
393 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 or ...
mark's user avatar
  • 379
2 votes
3 answers
2k 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 ...
BON's user avatar
  • 123
16 votes
3 answers
13k 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 error....
Peter.O's user avatar
  • 33.1k
8 votes
2 answers
6k 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 "$...
ДМИТРИЙ МАЛИКОВ's user avatar
2 votes
2 answers
897 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/'" "$...
Petr's user avatar
  • 165
11 votes
2 answers
21k 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 <?
hakre's user avatar
  • 433
38 votes
2 answers
51k 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 the ...
2NinerRomeo's user avatar
2 votes
2 answers
2k 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 ...
0xFF's user avatar
  • 381
0 votes
3 answers
3k 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 ...
LanceBaynes's user avatar
  • 40.6k
10 votes
5 answers
5k views

find not recursive when given a pattern on the command line

Imagine a source tree. There are xml files everywhere. But since there is a XYZ.xml at the root of this tree it won't find my xml files. find -iname *.xml returns ./XYZ.xml instead of ./XYZ.xml ....
Olivier Toupin's user avatar
6 votes
2 answers
535 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 this ...
user avatar
10 votes
1 answer
14k 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 ...
Amir Afghani's user avatar
  • 7,283
2 votes
2 answers
484 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 ...
David S.'s user avatar
  • 5,609
5 votes
3 answers
6k 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} ...
Stann's user avatar
  • 2,209
5 votes
2 answers
46k 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 ...
Abhishek Anand's user avatar
39 votes
3 answers
5k 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, ...
user unknown's user avatar
  • 10.6k
29 votes
3 answers
30k 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);}"' I'...
Seamus's user avatar
  • 3,713
10 votes
2 answers
5k views

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

I used to use '' and "" (single and double-quotes) 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 ...
apoorv020's user avatar
  • 1,283
12 votes
2 answers
8k 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. ...
badp's user avatar
  • 2,977
217 votes
3 answers
105k 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?
xenoterracide's user avatar
33 votes
4 answers
14k 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 ...
Leo Alekseyev's user avatar
6 votes
1 answer
10k 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 ...
Kumar's user avatar
  • 913
497 votes
10 answers
213k views

How do I delete a file whose name begins with "-" (hyphen a.k.a. dash or minus)?

How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory: tohru:~ $ ls -l total 8 -rw-r--r-- 1 me ...
Astra's user avatar
  • 5,073
17 votes
3 answers
59k views

Remote for-loop over SSH

I have the following in a script for server in ${servers[@]}; do echo ${server} ssh user@${server} "for i in /tmp/foo* ; do echo ${i}; done" done But it doesn't work. Weird thing, I see $I ...
Eldelshell's user avatar

15 30 50 per page
1
18 19 20 21
22