Skip to main content

Questions tagged [quoting]

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

1 vote
1 answer
353 views

To what does an unquoted empty variable expand in bash?

To what value does an unquoted, undeclared variable expand to in order to return an exit status of 0? Here is an example of a particular situation I ran into: [ -n $var ]; echo $? 0 [ -n "$var&...
twan163's user avatar
  • 5,700
18 votes
4 answers
5k views

Is there a command to write text to a file without redirection, pipe or function?

Pipes and redirection are two of the most powerful functions in Linux, and I love them. However, I'm stuck with a situation where I need to write a fixed piece of text to a file without using a pipe, ...
Paddy Landau's user avatar
1 vote
1 answer
332 views

Using variables for Ghostscript options/flags causes errors

I am scripting the creation/manipulation of PDF files so I am using gs (Ghostscript). The problem I am having is that if I use a variable for the the options, gs errors out. The command that I am ...
Allan's user avatar
  • 1,060
5 votes
3 answers
5k views

Escaping double quotes inside command substitution

I am attempting to write a simple bash parser. I am following the steps in this wiki. One of the assumptions I make is that I can do a pass over the entire input string and remove all single and ...
falky's user avatar
  • 189
1 vote
1 answer
973 views

Command substitution inside double quotes

I am attempting to write a bash parser. Many resources have referred to this wiki One area I am getting stuck is why the following would work echo "$(echo "hi")" # output => ...
falky's user avatar
  • 189
1 vote
2 answers
226 views

How to construct bash command and arguments for ssh / su -c

I'm backing stuff up from an array list of sources, a bit like this simplified version: sources=( file1 file2 "other stuff" ) backupcommand="rsync -ar ${a[@]} dest/" su backupuser -...
artfulrobot's user avatar
  • 2,949
2 votes
3 answers
4k views

-perm flag in find

I'm trying to wrap my head around this command: find /home/ -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null I understand that it's going to look in the 'home' directory for all directories ...
flowermia's user avatar
  • 141
1 vote
1 answer
708 views

RemoteCommand with percent signs doesn't work

The following command tmux new -A -s $(date +%Y%m%d%H%M%S) works and starts tmux with a session, named after current datetime (as expected). But if I put the same in ssh config RemoteCommand tmux new ...
Dims's user avatar
  • 3,285
2 votes
3 answers
317 views

How to double quote a wildcard pattern of files?

I've seen a bunch of similar questions to this one but none exactly the same. I have a directory of files which I want to pass in as a single, double-quoted argument to a command, using wildcard ...
Michael Kolber's user avatar
2 votes
1 answer
2k views

Error while executing adb shell command

adb shell am broadcast -a com.test.app --es command "STOP" --es filename "sample 1.01.49 7-09-1380(01).apk" I am trying to broadcast intent using the above adb command, where ...
Anonymous's user avatar
0 votes
1 answer
30 views

how to arrange quotes in this bash command

my_cmd --attr1 $(($1-$2)) --attr2 $(($1-$2+$3)) --attr3 $(($2+1)) I have this command and I would like to debug it (put it in echo and see how command will look like) but I am struggling with ...
quester's user avatar
  • 293
0 votes
2 answers
75 views

Why are aliases skipped if escaped?

A common way to skip aliases is to add a backslash before the aliased command. For example, $ alias ls='ls -l' $ ls file -rw-r--r-- 1 user user 70 Jul 30 14:37 file $ \ls file file My research has ...
Quasímodo's user avatar
3 votes
1 answer
2k views

What's the difference between test command and individual conditional expression surrounded by [[]]? [duplicate]

I am learning the zsh in the conditional expressions part, and I found some unreasonable output. For example: $ mkdir emptyspace && cd emptyspace $ var_assigned_with_emptystring="" $...
Anon's user avatar
  • 405
0 votes
1 answer
244 views

dash: How can I quote the arguments ala "${(q+@)@}" in zsh?

I want to quote the arguments in dash (or sh, or even bash if that's not possible). I can do that with "${(q+@)@}" in zsh, such that reval <sth> ... is the same as just typing in <...
HappyFace's user avatar
  • 1,620
1 vote
1 answer
250 views

What does " command do in terminal? [duplicate]

Recently, I opened terminal and started typing everything i can, after which i accidentally put " and something like python shell was initialised: muhammadrasul@AMR:~/Desktop$ lksdflaflakd;kfa;lk&...
Michael Adams's user avatar
-1 votes
1 answer
900 views

bash while loop irritate with single quote

I have a few lines code. I just want to check if argument $1 is in the file with a while loop so I write this code. #!/bin/bash if [ ! -z $1 ] then update=$1; while read line do if ...
Mahdi's user avatar
  • 19
-4 votes
1 answer
45 views

What is the meaning of !"?

The command echo !" returns an error message. But the command echo "Hello!" succeeds. Is it correct to use the command echo "Hello!" ?
tmpbin's user avatar
  • 783
0 votes
1 answer
70 views

Printing all lines between two strings, with one as a user input, using sed [duplicate]

I'm trying to use: sed -n '/String1/,/String2/p' Filename to print all lines between String1 and String2. Although I want to add String1 as a user input so, read $userinput sed -n '/$userinput/,/...
Richard's user avatar
1 vote
1 answer
287 views

UNIX KSH - Using double quotes or no quotes when assigning strings with wildcard to a variable?

I am new to UNIX and currently working on a shell script where I will be receiving files with names such as abc_123_date.zip so the file names will be abc_123_12312005. Instead of hardcoding abc_123_*....
ganq's user avatar
  • 11
28 votes
8 answers
40k views

awk print apostrophe/single quote

Can't figure out how to escape everything while using awk. I need to enclose each input string with with single quotes, e.g. input string1 string2 string3 output 'string1' 'string2' 'string3' Been ...
Artem S. Tashkinov's user avatar
1 vote
2 answers
382 views

How to execute function within double quotes?

I have these function: #execute vim and then exit on err return ve() { vim "$@" || exit } export -f ve #compile c source -> asm source in new tab in xfce terminal casm() { [ -z ${1} ] &&...
Herdsman's user avatar
  • 350
1 vote
2 answers
668 views

Problem sending SMS text with a single quote character - mmcli (ModemManager)

This is an example from the mmcli manpage: mmcli -m 0 --messaging-create-sms="text='Hello world',number='+1234567890'" The details how it is parsed are unclear, the description says only --messaging-...
VPfB's user avatar
  • 801
0 votes
2 answers
701 views

How can I define and use `alias` within `bash -c` with a one-line command?

I am trying to define and use alias within bash -c with a one-line command. The command: bash -c "eval $'df'" works fine, but: bash -c "eval $'alias df5=df\ndf5 -h'" doesn't. Why, and how can I ...
Franck Dernoncourt's user avatar
1 vote
2 answers
1k views

How to escape a "\" in command parameters [duplicate]

I have a command path/to/forticlientsslvpn_cli --server <host>:<port> --vpnuser testpass\101 When I run the script, linux puts a space between testpass and 101. I want the script to see ...
Tlou Rammala's user avatar
0 votes
2 answers
232 views

How to expand variable within a single-quoted argument?

I am trying to perform the following without luck: SORT_BY='-k3,3r -k2,2 -k1,1r' awk 'NR<4{print $0;next}{print $0 | sort '"${SORT_BY}"' -t"~"}' I have tried with all sorts of quotes, unquote, ...
Whimusical's user avatar
1 vote
1 answer
521 views

sed bash script is unexpectedly replacing character with space instead of newline [duplicate]

Using bash command syntax: echo "The*quick*brown*fox"|sed s/*/\\n/g I get the desired output: The quick brown fox However in script: IN_TXT="The*quick*brown*fox" OUT_TXT=$(echo $IN_TXT|sed s/*/\\...
SPB's user avatar
  • 13
0 votes
2 answers
4k views

using awk to print backslash

I am having trouble printing (or searching) for sequences containing backslashes when using awk For example - echo "test\test" | awk '{ gsub(/\\\\t/, "\\\\&"); print }' will give the result: ...
tomer's user avatar
  • 1
1 vote
1 answer
2k views

Why does echo `ls -l` does not have newlines? [duplicate]

I am running WSL (Windows Subsystem for Linux) and when I use the ls -l function on the terminal, I get new lines printed i.e. each file is on a new line e.g.: total 12K drwxrwxrwx 1 user user 4.0K ...
user12055579's user avatar
0 votes
1 answer
233 views

Output double quotes and variable

I'm writing a script to automate Let's Encrypt in PowerDNS,(this is a simple bash shell script to be run on debian) Certbot runs and calls the script, feeding to it the variable: $CERTBOT_VALIDATION ...
mike's user avatar
  • 1
1 vote
1 answer
122 views

I am confused with how to quote quotes

Hi I'm abolutely new to bash and coding in general. I have this screen command that I want to execute. I am already running Minecraft console on the screen "ftb": screen -S ftb -p 0 -X stuff "tellraw ...
Yanik's user avatar
  • 13
6 votes
1 answer
702 views

Script not working when passed to bash via -c

Why does this work: $ cat test.sh #!/bin/bash cat <(date|awk '{print $1}') $ ./test.sh Thu but not as a command passed to bash: $ bash -c "cat <(date|awk '{print $1}')" Thu 2 Apr 2020 12:52:...
Robin Moffatt's user avatar
0 votes
2 answers
737 views

Sed(?) is stripping backslash character from quote

I'm replacing a string with another string that includes escaped quotes: echo "replace FOO" | sed -e "s~FOO~test\\\"test~g" What I would expect is to see replace test\"test. Instead I see replace ...
Malcolm Crum's user avatar
1 vote
2 answers
373 views

How can I parameterise my command in a bash script file?

Edit -- Not using bash $1 variables. Example is using field designators: $1, $2, $3 are the awk input record fields Unfortunately I did the example too quickly and mixed-up the example. I believe ...
will's user avatar
  • 518
0 votes
1 answer
246 views

Backticks evaluation problem in quoted command, in su -c, in heredoc, fed into 2 layers of ssh

I have the following chain of indirection: ssh -t root@host1 ssh host2 << EOF\nsu - user2 -c 'kill `cat ~/file_with_pid`'\nEOF In the end what I need is just to kill a process (reading the pid ...
Michele Piccolini's user avatar
3 votes
2 answers
954 views

Globbing within a parameter expansion

I'm trying to select the files within a set of directories passed as arguments with the following: ${@/%/*} However, this is not ideal, since paths with spaces will break, and quoting the parameter ...
Xerz's user avatar
  • 131
0 votes
1 answer
309 views

Quoting a command line argument containing a variable that may have both single and double quotes in its expansion

After some unsuccesful attempts at quoting the command string correctly, I ended up using the below command to run the identify command on the .jpg files under the working directory, the names of ...
detic's user avatar
  • 33
5 votes
3 answers
1k views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
Porcupine's user avatar
  • 2,056
0 votes
3 answers
842 views

echoing Command to cron.d

I am trying to append/echo a command to cron.d. However, when running the script that echoes the command: echo */2 * * * * /usr/bin/aws ssm-send-command --document-name "AWS-RunShellScript" --...
ryekayo's user avatar
  • 4,763
0 votes
3 answers
736 views

Utility to add quotes to argument

I have an issue which can be solved with utility to add quotes to argument and output to standard. I did a web seach for "linux utility to add quotes to argument" and found nothing relevant. Is there ...
Marisha's user avatar
  • 343
2 votes
1 answer
231 views

Single quote problem in "sh -c" script launched from "find"

Now I am writing a script for a long time, but lately this problem has drives me crazy. I tried everything but couldn't solve it. find . -iname "*.mp4" -type f -exec ffmpeg -i "{}" -c:a "$ACODEC" -c:...
user avatar
2 votes
1 answer
24k views

Replacing '\'' with sed

I want to replace '\'' in a text file to another word or character using sed command. Tried using sed "s/'\''/×/g" but it doesn't work. Anyone know the solution?
IISomeOneII's user avatar
0 votes
1 answer
7k views

I received error "bash: line 1: [: -ne: unary operator expected" after run the below script

This script provides the expected output, but throw the error "bash: line 1: [: -ne: unary operator expected". Techies help to fix this. #!/bin/bash USR="root" # Email SUBJECT="NTP Service Status ...
sri's user avatar
  • 21
1 vote
1 answer
616 views

problem escaping quotes in script

I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this : mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
david furst's user avatar
-1 votes
1 answer
169 views

Bash ANSI C quoting not correctly quoting newlines

ANSI C Quoting in bash is supposed to read strings the same way C(or python with single quotes) would. printf $'"Hello, World!\\n"' #expected output (no newline, the slash is escaped) "Hello, World!...
Angular Orbit's user avatar
2 votes
2 answers
368 views

What is the right way to quote nested parameter expansions?

When dealing with with nested parameter expansions, which of these is the correct way to quote things? This one: var="${var#"${var%%[![:space:]]*}"}" Or this one: var="${var#${var%%[![:space:]]*}}"...
Harold Fischer's user avatar
0 votes
1 answer
1k views

Quote a special character in a script file using awk

So I'm looking to write a script file which takes in a user-inputed number, and based off that number, it will execute a certain command. This command is the awk command that, of course, uses a field ...
Jake M's user avatar
  • 101
0 votes
1 answer
660 views

how to use quotes in sed & ssh?

i cant get this to work in bash/rhel 7: ssh host "sed -i -e \"s/dnl MASQUERADE_AS.*\$/MASQUERADE_AS(\`domain.com\')dnl/\" /etc/mail/sendmail.mc" bash: -c: line 0: unexpected EOF while looking for ...
darchon's user avatar
  • 11
0 votes
1 answer
542 views

Why do these rsync filter args fail in bash when passed in array?

Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}"...
markling's user avatar
  • 213
4 votes
2 answers
1k views

Is there a way to printf $@ verbatim?

I want to write a script that echoes to stdout its $@ verbatim, including any potential double-quotes, without a newline. What I have tried: > cat ./script1 #! /usr/bin/bash printf "%s %s" $0 ...
StoneThrow's user avatar
  • 1,797
0 votes
2 answers
2k views

How can I pipe sed output to printf for formating?

I am using Tecplot to process wind tunnel data, but the input for Tecplot requires a specific format for variable specification; each variable is bracketed by double quotes "Variable Name". The ...
Stephen Alter's user avatar

15 30 50 per page
1 2
3
4 5
22