Questions tagged [quoting]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
52 views

Issues setting a variable to a string containing metacharacters, find, and another variable in csh

I'm using csh for a project (forced into it, sorry), and one component of my script uses variations of the following in a large block of its functionality: find . -maxdepth 1 -not -type d | awk '{...
4
votes
2answers
2k views

Escape double quotes in variable

I would like to put this command into a file to be run later: ln -s "$xr"/ya.txt ~ I can do that with (1): cat > zu.sh <<eof ln -s "$xr"/ya.txt ~ eof or (2): printf 'ln -s "%s"/ya.txt ~\...
15
votes
2answers
1k views

How are double quotation marks in bash matched (paired)?

I am using GNU bash 4.3.48. Consider the following two commands that only differ by a single dollar sign. Command 1: echo "(echo " * ")" Command 2: echo "$(echo " * ")" The output of them are, ...
4
votes
3answers
3k views

awk in ssh command line complains 'unexpected newline or end of string' How to resolve?

While running the below script had an issue, ^ unexpected newline or end of string How could I resolve this ? [root@emrbldbgdapd2 ~]# ./collectdata.sh collect the data of 10.209.61.124 awk: cmd. ...
0
votes
1answer
60 views

script parameter containing spaces invoking mediainfo

I'd like to create a small shell script that will tell me the duration of a video whose file name is passed to it as a parameter. It'd be something like this: $ script_name "file name with spaces....
0
votes
3answers
483 views

Can’t echo variable value=* in script [duplicate]

Content of myfile: 123 **1 ** Script that attempts to display each word: for i in $(cat $myfile) do echo "$i" done the result is when echo *, it lists the files in my current ...
2
votes
0answers
60 views

Bash: Special variables $@ vs. $* in For Loop [duplicate]

Using $@ instead of $* would preserve quoting. Consider the following script: #!/bin/bash # Test.sh for arg in $@ do echo "I found the argument $arg" done ./Test.sh "One Two Three" I reach the ...
0
votes
2answers
193 views

What does “newline” mean in the bash documentation?

The bash documentation says the following: A non-quoted backslash ‘\’ is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of ...
4
votes
4answers
4k views

Backslash in variable substitution in Bash

I was working on a Bash script to help partition a hard drive correctly, and I came across a strange problem where I had to append a number to a variable. It took me a while to get the outcome right ...
6
votes
3answers
843 views

bash quote escaping change in 4.4

I am updating bash on our embedded platform from 4.1.9 to the latest (4.4.12), and I am seeing a behaviour change in this simple scenario of passing escaped arguments into a script. Script /tmp/...
1
vote
2answers
3k views

Why is using eval necessary to pass quoted arguments

I have the following example. #!/bin/bash ARGUMENTS="-executors 1 -description \"The Host\" " # call1 # error: parameter Host" is not allowed java -jar swarm-client.jar $ARGUMENTS # call2 # ...
11
votes
3answers
2k views

How do ssh remote command line arguments get parsed

I've seen the questions and answers about needing to double-escape the arguments to remote ssh commands. My question is: Exactly where and when does the second parsing get done? If I run the ...
1
vote
2answers
1k views

bash escaping quotes

I have an interesting challenge for how to escape quotes in a bash script. My bash script has a long curl call with a large -d json structure passed. #!/bin/bash Value4Variable=Value4 curl -s -X ...
0
votes
2answers
61 views

Can you use variables inside $'…' in bash?

I have tried the following: myprogram $'Hello $HOME' But it did not work (the command line argument received by myprogram was Hello $HOME, and not the value of $HOME).
3
votes
1answer
813 views

Double Quotes in Bash's variable substitution

I am trying to configure some software packages with a script thereby I got the following problem. Assume that the environment variable PREFIX is set to the location where I plan to install the ...
2
votes
4answers
99 views

$'\n' in double quotes does not work

I want to send a string that contains the newline character as a command line argument to my program, the following works: myprogram Hello$'\n'World But when I use double quotes on the string: ...
3
votes
3answers
185 views

Enclosing vs. not enclosing a variable's value in quotes in bash [duplicate]

When I do something like this: x="hi echo hello" or x='hi echo hello' Then x will contain the string hi echo hello. But when I don't use quotes: x=hi echo hello Then x will contain the string ...
0
votes
2answers
50 views

Why the spaces are not being printed in this for loop? [duplicate]

I have this code: for i in 'some text' "some other text" do echo $i done The output is: some text some other text Why the spaces are not being printed?
2
votes
2answers
879 views

Are the single quotes and the double quotes handled by “bash” or by “echo”?

When you do something like this: echo 'Hello World' Or like this: x=12345 echo "x is: $x" In the first example, does the echo command receive 'Hello World', or does it receive Hello World? And in ...
2
votes
2answers
97 views

shell variable test expansion problem

I have this code: sed \ $( (( $compress == 1 )) && echo -n '-e /^RMTHOST/ s/$/, compress/' ) \ -e "s|\*\*jobname\*\*|$jobname|g" \ -e "s|\*\*hostname\*\*|$hostname|g" \ -e "s|\*\*hostport\*\*|...
4
votes
5answers
407 views

sed using double quotes with \!b leads to unknown command on back slash

I currently have a sed command that I want to act on the following type of text: user: ensure: 'present' uid: '666' gid: '100' home: '/home/example' comment: ''...
4
votes
2answers
1k views

How does Bash handle quoting in the string replacement section of parameter expansion?

Is there any consistent logic to it? some-command "${somevariable//some pattern/'how does this get parsed?'}" I've posted some conclusions and raw tests below as an "answer" but they're not a full ...
5
votes
1answer
688 views

Writing a command to a script file with proper quoting

A situation that I've run into a few times: I have a shell function that does some setup and then invokes a more-or-less arbitrary command, like this: setup_and_run() { some_setup_commands "$@...
-1
votes
1answer
134 views

issue with double/reverse quotes in su - user -c command

I'm trying to execute this command but getting error due to double, single, reverse quotes. su - ctmagent -c "/usr/ctmagent/ctm/exe/ctmpsm -UPDATEAJF `/usr/ctmagent/ctm/exe/ctmpsm -LISTJOB NOTOK | ...
1
vote
1answer
109 views

grep not working when I enclose the directory in double quotes

When I do something like this: grep "hello" /home/paul/* It works. But when I do something like this: grep "hello" "/home/paul/*" grep display the error: grep: /home/paul/*: No such file or ...
1
vote
2answers
33 views

Bash - Parameter should not be parsed as bash while outputting

I do have 2 Shell Scripts. The first one triggers the second one and adds some parameters. The second one calls a command and adds the parameters from the first script as parameters for the command. ...
1
vote
2answers
482 views

Why does the command echo `echo \\\z` output \z?

The command echo $(echo \\\z) is from the book , I don’t understand why it outputs \z I think it should output z
0
votes
2answers
60 views

Reading output of command into variable in shell, splits text at every white space not just newline

I'm using sh (not bash/csh) on FreeBSD 11, and I don't understand this: In console Command: zpool status -v Result: pool: My_pool state: ONLINE status: One or more devices is currently being ...
0
votes
1answer
295 views

Shorthand syntax for U-Boot arguments

What is proper syntax for setenv bootargs command when using shorthand syntax for method? For example, the full kernel environment variables is U-Boot> setenv bootargs console=ttyS1,115200n8 ...
2
votes
3answers
585 views

How to display the command and avoid code injection

I'm playing with wget, and I basically do a script that download a page, grep some information on this page, and then wget another page depending on these informations. So basically, my code looks ...
0
votes
1answer
49 views

Having trouble with sqlite3 ssh command (I am assuming bad quotes)

The following works great: ssh plxch1035.pdx.xxxxxx.com "sqlite3 /p/hdk/rtl/proj_data/shdk74/fe_data/ipci/ipci.db 'select * from tools'" When I want a specific tool row though: ssh plxch1035.pdx....
-2
votes
2answers
1k views

Grep not working with variables, even with quotes

name=$(echo "$FILENAME" | grep -E '*\.(eng|por|pt-BR)\.*') Why this line doesn't work? if I do echo "Test (2013).1080p.por.mkv" | grep -E "*\.(eng|por)\.*" It works, I tried with "" without " and ...
0
votes
1answer
1k views

Bash script failing with unknown option due to space in argument [duplicate]

I am trying to run aws create lambda function. It goes as follows - eval $(aws lambda create-function \ --function-name $FUNCTION_NAME \ --runtime $RUNTIME \ --role $ROLE \ --handler $HANDLER \ --...
2
votes
2answers
4k views

How to use the ls ? option in a bash variable?

I want to use the ls ? option in a Bash variable. How do I get the script to do the same thing as ls -lt foobar_??????.log ? $ cat foobar_ls.sh #!/bin/bash FOOBAR_LIST="foobar_??????.log" ls -lt "$...
2
votes
1answer
383 views

Quoting a path that contains spaces, in FreeBSD - why doesn't it always work?

I have a directory on my FreeBSD server whose contents are created by Windows users over Samba. The filenames and paths within it sometimes contain spaces, as is common in the Windows world. I just ...
0
votes
1answer
291 views

Invoking zmv from bash

I have recently discovered this technique for renaming files using zsh: autoload zmv zmv '(*).JPG' '$1.jpg' which I can also write as: autoload zmv; zmv '(*).JPG' '$1.jpg' This works as advertised ...
0
votes
2answers
491 views

Why echo command does not need “-e” option when escaping “$” character with a backslash

This is regarding bash builtin echo. Per Bash documentation the -e option enables interpretation of backslash escapes. If I execute echo "Total Amount \$500", I see the expected output Total ...
43
votes
7answers
3k views

What's a good mnemonic for shell double vs. single quotes?

I don't do enough scripting to remember, without looking up, whether double or single quotes result in a Unix variable being substituted. I definitely understand what is going on. My question is does ...
1
vote
1answer
10k views

passing string containing spaces as command-line argument from within script

I'm using a bash shell on mac. I want to write a shell script 'gac' such that running > gac one two three produces exactly the same effect as running > git add . > git commit -m "one two ...
1
vote
1answer
386 views

A variable with quotes as a sed command produces an error

I have this script: num='[0-9]' sedcmd='-e "s/${num}/as df/g"' echo 123 | sed -r $sedcmd The last line produces this: sed: -e expression #1, char 1: unknown command: `"' What did I miss?
7
votes
2answers
3k views

How Can I Expand A Tilde ~ As Part Of A Variable?

When I open up a bash prompt and type: $ set -o xtrace $ x='~/someDirectory' + x='~/someDirectory' $ echo $x + echo '~/someDirectory' ~/someDirectory I was hoping that the 5th line above would have ...
0
votes
1answer
438 views

Do I need to double quote a variable?

I am confused on when we double quote shell variables. Specifically I am using the following sed replace command: sed -i.tmp "/$MY_VAR/d" /foo/bar/file.txt But I am not quoting $MY_VAR. Is this ...
2
votes
2answers
90 views

Mixing local and remote variables and proper usage and quotation

The recommended pattern for bash as far as I know is to always quote the shell variables. E.g. "$VAR" instead of $VAR. But how can I achieve the same safety the quotes provide for variables meant to ...
2
votes
4answers
1k views

Avoid escaping of double quotes

I have some commands I want to execute in a bash script. Now when we use single quotes the variable is taken literal and not the value. So doing e.g. ls "$SOME_DIR" is not the same as ls '$SOME_DIR' ...
0
votes
1answer
48 views

Why doesn't this command work like I expect? [closed]

cat $(echo this\\ list) Seems like it should be the same as cat this\ list but it isn't. I know that I can use cat "$(echo this\\ list)" but then I can't echo multiple files into cat. Why doesn'...
2
votes
3answers
943 views

How do I invoke jq inside awk?

Essentially I have a file.log as follow blah blah blah blah Hello world | {"foo": "bar"} blah blah Hello earth | {"foo1": "bar1"} Now my goal is to write some shell commands to have desire output ...
2
votes
1answer
153 views

Nested quotes nightmare : sending an e-mail from a remote host

I need to send (from my terminal) an email with attachments from my remote host which I access by ssh. I already know that to do something remotely, I use ssh -p myport myusername@myhost.com "...
-2
votes
2answers
126 views

why command not working properly when wildcard is detected

segment of code from shell script fname=$(sed 's/(.*//' <<< $p | awk '{ print $NF }') if [[ $fname == *['!'@#\$%^\&*()_+]* ]] then flag1=0 fi where $p is one line from a text ...
3
votes
1answer
598 views

Bash script can't find command if quoted

I have a bash script to run a command across multiple directories. This works fine when called like so: $ ./run git status However when quoting the sub-command, I get 'Command not found' errors. $ ....
2
votes
1answer
184 views

Bash: History expansion inside single quotes after a double quote inside the same line

I took a closer look on this phenomenon after I stumbled over it in two other questions today. I've tried all of this with the default set -H (history expansion on). To test a script, I often do ...