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
2
votes
2answers
221 views

How to prevent symbols in an environment variable from escaping?

I'm trying to write a shell script, and to make it more or less readable, i decided to bring a part of my commands into environment variables: #!/bin/bash # Variables name_expression="-type d \( -...
2
votes
1answer
2k views

Passing arguments with spaces and quotes to a script (without quoting everything)

The following works great on the command-line: $ ffmpeg -i input.m4a -metadata 'title=Spaces and $pecial char'\''s' output.m4a How do I parameterize this command and use it in a script/function? I ...
1
vote
1answer
2k views

Escaping in double quotes in bash scripts

I am confused on this topic when reading the Advanced Bash Scripting Guide. According to the book, Bash script, when we quote a string, we set it apart and protect its literal meaning. And ...
2
votes
1answer
4k views

Send variable with EOF and use host variable [duplicate]

I want to send variable from source to host, and exec host script. Here is my code : var1=1 ssh -p 42 root@xxx /bin/bash << EOF var2=2 echo $var1 echo $var2 EOF Return : 1 var1=1 ssh -...
1
vote
1answer
682 views

How do I join an array of strings where each string has spaces?

My bash script: #!bin/bash MY_ARRAY=("Some string" "Another string") function join { local IFS="$1"; shift; echo -e "$*"; } join "," ${MY_ARRAY[@]} I want the output to be: Some string,Another ...
-4
votes
1answer
73 views

Folder exclusion formatting issue

I'm trying to create make targets for flawfinder and cppcheck that will recursively search the current directory, but ignore directories named "Test". However, I have run into some issues with ...
0
votes
2answers
227 views

What is the difference between '*.txt' and *.txt?

I was completing the git tutorial found here: https://try.github.io/levels/1/challenges/7 And it said that I had to put single quotes around *.txt. I had not seen this before when using linux but ...
17
votes
3answers
2k views

Why do options in a quoted variable fail, but work when unquoted?

I read about that I should quote variables in bash, e.g. "$foo" instead of $foo. However, while writing a script, I found an a case where it works without quotes but not with them: wget_options='--...
0
votes
2answers
714 views

find: missing argument to `-exec' in Cygwin

I am trying to get HTML files from component folder and building new component folder and trying to insert that component (New) folder in build folder for Which I am using the given code: find ...
4
votes
3answers
1k views

quotes inside backticks inside quotes in ksh

I'm trying to get the file of the current date with the following command in HP-UX Unix: $ ls -lrt ABC.LOG* |grep "`date +"%b %d"`" But, it's giving me the error: ksh: : cannot execute grep: can't ...
1
vote
1answer
53 views

Shell expansion not happening

Why are these two commands equivalent (or so it seems based on the results I get back)? I figured the first command wouldn't work because the * would be treated as the glob operator but instead it got ...
5
votes
4answers
5k views

Properly escaping output from pipe in xargs

Example: % touch -- safe-name -name-with-dash-prefix "name with space" \ 'name-with-double-quote"' "name-with-single-quote'" \ 'name-with-backslash\' xargs can't seem to handle double quotes:...
0
votes
1answer
468 views

Subshell inside quotes

I'm writing a small shell script like this: curl -X POST --header 'Bearer "$(printf user:pass | base64)"' 'https://api.com/v1/auth' To debug I switched to echo: echo 'Bearer "$(printf remote-key-...
2
votes
1answer
1k views

Problems creating array with newline separator

I'm building a function to find large directories on the filesystem and the /n is being cut off of /native/proc... in each of my array elements containing that path. I believe this has something to ...
0
votes
1answer
101 views

ls -l seems to give one concatenation of the filenames found in a directory

I want to write a shellscript to convert all .ogg files in a directory to .mp3 files. The filenames contain spaces, so I use a lot of double quotes in the sequenco of commands. The command I use is ...
2
votes
2answers
221 views

Why is it not required to double quote `$bar` in assignment `foo=$bar`? [duplicate]

From https://unix.stackexchange.com/a/32227/674 The main places where it's safe not to use the double quotes are: in an assignment: foo=$bar (but note that you do need the double quotes in ...
0
votes
2answers
87 views

Loop space directory name [duplicate]

I have a CT.txt with below input data. CT.txt: test testing test 1 And with below script: #!/bin/bash for CITY in $(cat /home/user/CT.txt) do FILES=/mnt/dir1/dir2/$CITY/* echo $FILES Giving me ...
1
vote
2answers
2k views

Why is this environment variable not set up?

When a shell runs an external executable as a command, we can pass environment variables into the executable. $ var=3 /bin/echo `$var` $ var=3 bash -c "/bin/echo '$var'" both don't output anything. ...
0
votes
3answers
610 views

Pass parameter to single quoted command

I'm trying to run a script: #!/bin/sh A=multichain-cli chain97 issue 1XRnkvTc1Ev3q8UnSyynu1Qb9ss1E3aJWZn2bQ '{"name":"Test_Asset","open":true}' 100 echo "$A" exit I'm trying to pass Test_Asset ...
3
votes
4answers
832 views

Bash: escaped quotes in subshell [duplicate]

When I execute the following command: #!/bin/bash while IFS= read -r -d '' file; do files+=$file done < <(find -type f -name '*.c' -print0) echo "${files[@]}" I do not get the same result ...
2
votes
3answers
1k views

Xargs With Multiple Argument Substitutions - Use environment variable argument after sh -c '…'

This is my command: find $1 -name "*.html" | sort -n | xargs -I {} sh -c 'echo "Dumping file: "{} >> "$2"; w3m {} >> "$2" 2>&1' where: $1 is the path where I will look for files ...
5
votes
3answers
9k views

find and replace with sed with slash in find and replace string

I want to change in file /var/www with /home/lokesh/www with sed command sed -i 's///var//www///home//lokesh//www/g' lks.php but this give error sed: couldn't open file ww///home//lokesh//www/g: No ...
1
vote
2answers
366 views

Here-document without interpreting escape sequences, but with interpolation

Is there any way to cat a file without interpreting the double backslash as an escape sequence? In this example a tex file is created: cat <<EOF > file.tex \\documentclass[varwidth=true,...
2
votes
1answer
146 views

Strange output with command subtitution using backticks in bash script

echo "testing:" PROXY_URL="/proxyurl/" proxyUrlSedEscaped=`echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g'` echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g' echo "$...
1
vote
1answer
97 views

How to pass a value that has to be in quotes to a command?

I am trying to make a script which will use ffmpeg to record the screen and audio. The user will be able to choose what will be recorded: only screen, only microphone, only speakers sound or ...
1
vote
2answers
6k views

How can search for both single quotes and double quotes in a grep search?

When I do a search bindkey in the zsh plugins directory for key conflicts I get responses from both the .zsh script files and .md files, and some of the zsh readme files use a double quote in the ...
0
votes
3answers
102 views

find command with multiple pattern not returning any output

#!/bin/bash pat="'*.ab' -o -name '*.bc'" open="\(" close="\)" path=path find $path -type f $open -name $pat $close Above code doesn't show any output for find. Do help
10
votes
1answer
430 views

Do shells other than Bash and Zsh support ANSI-C quoting? e.g. $'string'

I have a shell script that uses the following to print a green checkmark in its output: col_green="\e[32;01m" col_reset="\e[39;49;00m" echo -e "Done ${col_green}✓${col_reset}" After reading about ...
4
votes
3answers
6k views

shell test whether multiple lines string contains specified pattern in last line

I want to determine whether a multi-line string ends with a line containing specified pattern. These code failed, it doesn't match. s=`echo hello && echo world && echo OK` [[ "$s" =~ ...
3
votes
1answer
5k views

bash add property using variable with jq

To add a property to a JSON text I manage to use result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent") But if I want to replace "someValue" by a variable: result=$(jq -c '....
1
vote
3answers
2k views

echo $ along with variable

Im trying to do print last directory like below #!/bin/bash dirc="/a/b/" i=3 `echo "$dirc" | awk -F / '{ print ""$"i"}'` which should print 'b', which is not happening.
4
votes
1answer
2k views

Find a file and make a symlink to parent using find and -exec

I am trying to use find to find files matching a certain pattern, and then symlink their parent directorys to another directory, this is my current script (I'm doing this on mac so -printf won't work ...
1
vote
4answers
330 views

An Alias for Moving Files and Following Them to Their Destination

I’m trying to write a script – or an alias, to be more precise – which allows me to move files and follow (cd) them to their target directory. The accepted answer to this question suggests this code: ...
0
votes
2answers
265 views

-bash: !'@10.109.10.142/?ip=10.109.8.39: event not found

I have this command: ovftool --acceptAllEulas -ds="Local_Storage_1_39" -n="VR-OVF" --net:"Management Network"="VM Network 2" --prop:"password"="R3d@ctedPassw0rd!"$a" --prop:"ntpserver"="10.109.10.140"...
3
votes
2answers
2k views

Is there a way to execute code in the command line prompt (PS1) without using backticks?

I am using this piece of code directly in the command prompt (PS1), and it tells me whether the previous command executed correctly. PS1="\`if [ \$? = 0 ]; then echo -e \"\e[1;32m[⚡️ ]\"\e[0m; else ...
0
votes
1answer
480 views

Alias accepting variables from the result of evaluation [duplicate]

I was trying to define an alias that helps me to cd to the directory that is created most recently, and I'm using the following in my .bashrc: alias cdlatest="latestdir=$(ls -td -- */|head -n 1); cd $...
0
votes
2answers
576 views

Find size of file names with space and hyphen | pass file names containing space and hyphen to “du” [duplicate]

I have a file, which contains the name of some files. I want to find the total size of files in the list. #cat filelist /tmp-directory/connector_db_ connector_db /tmp-directory/connector_db -...
1
vote
1answer
479 views

stat --format %N quotes

I used stat on two different versions of Ubuntu and it printed different types of quotes. 14.04 (coreutils 8.21-1ubuntu5.1): $ stat --format %N test.txt ‘test.txt’ 16.04 (coreutils 8.25-2ubuntu2): ...
3
votes
1answer
766 views

Filenames with spaces in backtick substitution

Suppose I have a file containing a space in its name such as with space. What should cmd output in the below snippet for ls to accept 'with space' as argument? $ ls `cmd` I tried ls `echo 'with ...
2
votes
2answers
2k views

execute windows program with parameters from cygwin

I want to execute a windows program in cygwin console. I have tried various forms but I don't find the correct syntax. $ cmd /C "C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe format ...
1
vote
1answer
748 views

Basic syntax explanation for variables in bashrc

I want to correctly export a variable. In order to do so I have to understand several variations in syntax. I've seen the following mechanisms of exporting a variable. In this case I am using ....
4
votes
1answer
248 views

How to deal with filenames containing a single quote inside a zsh completion function?

I'm using the zsh shell and have the following code inside my .zshrc: fpath=(~/.zsh/completion $fpath) autoload -Uz _vc autoload -Uz compinit compinit The first line add the path ~/.zsh/completion ...
1
vote
1answer
80 views

Why can't I switch to a virtual avfs directory with quotes?

I installed avfs to be able to transparent mount archive files as directories. I created a mount point with: mkdir ~/.avfs avfsd ~/.avfs From there, I can do things like cd ~/.avfs/some/path/foo....
0
votes
2answers
731 views

If condition not working in script over ssh

Below shell script on SSH mode is not working. variable end_pos is getting value "Stop", but when it comes in IF loop , it doesn't check the condition and loop is getting failed. Output of command : ...
2
votes
2answers
589 views

Parallelizing sed gives different output

Trying to parallelize a sed operation however, while the parallel version works, it gives back a wrong output. The sed operation that I would like to parallelize (works) sed 's/\s.*$// ; s/\(.*\)/\L\...
4
votes
1answer
878 views

Prevent GNU parallel from splitting quoted arguments

I'm trying to use GNU Parallel to run a comman mutliple times with a combination of constant and varying arguments. But for some reason the constant arguments are split on white-space even though I've ...
2
votes
1answer
91 views

Problem with escaping parameterised arguments

I feel really reluctant to ask this question as it feels like I must be missing something really obvious. However, I am unable to find existing questions with exactly the same problem. We have a ...
0
votes
1answer
154 views

ls -td fails to identify any directories

I'm having a bit of a problem working on a shell script. One of the commands within the script is used to push a set of commands from a Jenkins host to MySQL database hosts to run backups "locally" to ...
6
votes
2answers
177 views

Do I need to quote command substitutions when assigning their output to a variable? [duplicate]

I tend to quote command substitutions as shown below even when assigning their output to a variable: var="$(command)" Is that actually needed though? When does it break? The accepted answer here ...
4
votes
3answers
3k views

Escape [ in grep

I read strings from stdin and I want to display the users that match the strings. Problem is, if the user inputs the character '[', or a string containing it. grep -F does not work because the line ...