Questions tagged [quoting]
Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.
1,076
questions
3
votes
1
answer
2k
views
prevent single quotes in bash script
I have a bash script that's just a shortcut to the grep command. I call it like this:
stx -p /var/www -t 'my text'
This would run this command:
sudo grep -rinI /var/www -e 'my text'
I'm trying to ...
2
votes
2
answers
1k
views
Meaning of 'wait $${!}' in docker-compose.yaml?
I am doing some docker with letsencrypt and nginx. In the tutorial I am following there is this command for the certbot container which allows for the sertificate to be checked for validity every 12h.
...
2
votes
1
answer
180
views
awking for command options from man page
I am trying to auto-generate tab-completions for different commands. I am piping man pages for different commands into awk, then searching for command line options (eg. -shortopt --long-option) ...
0
votes
2
answers
484
views
Quoting directory names in bash prompt
I want to quote the current directory in my prompt.
Eg, if I do:
mkdir $'new\nline'; cd $'new\nline'
I want my prompt to display $'new\nline', and NOT print a literal newline.
I'm seeing ...
4
votes
1
answer
788
views
Prevent awk from removing "\" (backslashes) in variable
I have this line of code for the shell:
ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" '{print "File Name: "$0"\n"here"\n"source}'
Unfortunately it outputs:
File Name: Data 00053....
0
votes
1
answer
3k
views
.bashrc not read on WSL if $HOME contains spaces
I recently: Specified a home directory path for a user in /etc/passwd with spaces in it? but now my .bashrc doesn't source properly when I open a Ubuntu 16.04 LTS WSL window, so I have to source it ...
4
votes
2
answers
20k
views
Escaping ' (single quote) in sed replace string [duplicate]
I have a script that I'm using to perform some iptables changes across servers. In the script I have a sed command to find a string and insert iptables rule before that line.
The problem I'm having ...
0
votes
1
answer
434
views
Splitting using newline character in bash command substitutions
Say I have a directory with three files with names including spaces: a b, c d, and e f. And I want to use vi to edit the first two files. The bash command I want is
vi "a b" "c d"
I also want to get ...
0
votes
1
answer
87
views
Find: Substitute expression with a variable
$ find -name "Bik*"
./Biking
./Biking/Unsync/Biking.md.~6~
./Biking/Rendered/Biking.gen.html
./Biking/Biking.md
Now when I substitute expression with a variable as follows:
$ a='-name "Bik*"'
$ ...
0
votes
1
answer
541
views
Why cat command redirect a new file get executed right away?
I want to generate a bash file that could be called later, like this
cat <<-SCRIPT >test-$$
#!/bin/bash
osType=$(grep -Po '^NAME="\K[^"]*' /etc/os-release)
if [ "$...
0
votes
3
answers
709
views
Quotes are being treated differently in backtick output [duplicate]
Background
I want to pass a list of filenames (listed via find) containing spaces to my custom python script. Therefore, I set up find to add quotes around each result:
find ./testdata -type f -...
0
votes
1
answer
45
views
Script Integer getting prefixed with "
I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior:
Script looks like this:
java -...
0
votes
2
answers
67
views
Why doesn't $() expand properly?
I want to play all the .mp3 files within a directory using vlc, so I do something like this:
vlc $(find ~/Documents/music -name "*.mp3" -exec "echo \"{}\"" \;)
The issue is that I get "vlc: unknown ...
2
votes
1
answer
71
views
replace specific characters containing "\" character with sed
I would like to replace the following sentence "lw 2,\" with the sentence "lw 2" however I cannot do it with
sed -i 's|lw 2,\|lw 2|g' "filname"
I get the following error
sed: -e expression #1, char ...
0
votes
1
answer
113
views
Make shell interpret operators enclosed in single-quotes [closed]
I have two commands built using the logical operator &&. The two commands are enclosed in single-quotes because they are to be passed as a command to root:
$ su -c 'sed -i '1i TEXT' file1.txt ...
5
votes
2
answers
22k
views
Environment Variables with $ Character [duplicate]
I'm using a MacOS. I tried to enter this environment variable inside my .bash_profile:
export CLOUD_PASSWORD=Pass4Aa$ditya
But when I do source .bash_profile and try echo $CLOUD_PASSWORD, I get this ...
6
votes
4
answers
6k
views
How to prevent command substitution on the command line?
I find that when writing text as input to another program, any command substitutions in double quotes within the intended text are interpreted and expanded by the shell
The links in the answer here ...
0
votes
2
answers
980
views
CSV fields max length error and setting quoting=csv.QUOTE_NONE
After running csvcut on a comma-delimited .csv file:
[root@server files]# csvcut -c title,mpn,overview,techspecs2,image_carousel_elargesrc syn_multi-image.csv > syn_scraped_cut.csv
I get the error:...
0
votes
0
answers
37
views
Escaping spaces with backslash [duplicate]
Not much context to it.
export essential='/Users/mac/Desktop/AP\ Prep/javatest/essentials'
cd "$essential"
Yields this error:
-bash: cd: /Users/mac/Desktop/AP\ Prep/javatest/essentials: No such ...
0
votes
2
answers
917
views
Find not working as expected with space in directory
I have a script calling this
find "/mnt/Data/Shared/$1" -type d -exec bash -c 'fixperm "'${1}'" "fd" "$0"' {} \;
$1 is a directory, when the name contains no spaces it works, when there is a space ...
3
votes
1
answer
3k
views
find: unknown predicate `-p'
find /log/ -mtime -31 -type f -name ""*data.txt"" -printf ""cp -p %p /Backup/%Td/\n"" | sh
I am trying to set up this command in a cron job and it's complaining about unknown predicate -p. Not really ...
6
votes
1
answer
2k
views
How do I tell GNU Parallel to not quote the replacement string
GNU Parallel quotes replacement strings by default so that they are not expanded by the shell. But in certain cases you really want the replacement string to be interpreted by the shell.
E.g.
$ cat ...
1
vote
2
answers
1k
views
How do I use awk's single quotes within another single quote phrase?
Background
I am running a command that dispays processes on multiple hosts. Below is the command:
execAll -m "$HOSTS" 'hostname; ps -ef | grep build | grep -v grep; ipcs | grep 666'
Attempt
I ...
-2
votes
2
answers
4k
views
How to execute a command that has many nested single and double quotes with a quoted variable in bash
Here is my simple script
#!/bin/sh
thefile=/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe
while inotifywait "${thefile}" ; do
a=\"`strings ${thefile} | tail -n 5 | head -n ...
1
vote
1
answer
4k
views
Escaping special characters &, $, ^, *, ! in unix command (bash perl)
Basically, I'm trying to send some email thru uucp to some especial accounts using the RFC 5322 standard that includes !#$%&'*+-/=?^_`{|}~; (https://en.wikipedia.org/wiki/Email_address#Local-part)
...
1
vote
2
answers
4k
views
Bash: Escaping double quotes in $() command substitution [duplicate]
I am having trouble wrapping my head around how command substitution works when part of the command's parameters come from a variable.
To illustrate, I'll just present a series of commands:
I'll ...
7
votes
2
answers
13k
views
How to render variables without quotes in bash script?
The following script:
$ cat runme01.sh
#!/bin/bash
A=myval
B=$A/{fix}
C=$A/fix
set -xT
echo $B
echo $C
prints the following if ran:
$ ./runme01.sh
+ echo 'myval/{fix}'
myval/{fix}
+ echo myval/...
3
votes
1
answer
4k
views
Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of ...
5
votes
2
answers
884
views
Use backslash or single-quotes for field separation
I have always been using single-quotes for the field separation like: awk -F';' ...
Quite new to me is the way of using a backslash like: awk -F\; ...
is there a technical difference for either, or ...
0
votes
1
answer
42
views
add a line to file that contains quotes and variable using bash
I want to add this line to /etc/grub.d/00_header
set superusers="ubuntu"
where ubuntu is the result of $USER.
I've tried this:
sudo bash -c 'echo "set superusers='"${USER}"'" >> /etc/grub.d/...
1
vote
1
answer
250
views
Command runs okay but not from bash script
Under ~/Pictures there are some sub-directories containing jpegs like
~/Pictures/Pics 1/img.jpg.
From bash:
~/Pictures $ `file Pics\ 1/img.jpg`
Output:
Pics 1/img.jpg: JPEG image data, Exif ...
0
votes
2
answers
2k
views
Run ssh command without quotes
You can execute a command on a remote server using
ssh user@host 'the command'
but is there a way to execute the command without quotes?
(I am on BSD and using OpenSSH)
4
votes
2
answers
624
views
Why must I not quote a string variable when running it as a command?
My Ubuntu/Debian-based Linux update POSIX shell script seems to require that I not double quote the string variable with the stored command, which is being executed. As I don't understand this issue, ...
4
votes
4
answers
3k
views
Correctly quote array that is being passed indirectly via another command
I need to pass an array of filenames to a command, preserving proper quoting. So far, so good. Unfortunately the command is actually a sub-command that is, in turn, invoked by another command. ...
0
votes
1
answer
77
views
Running command in a variable [duplicate]
It is often said that variables should be double quoted when used.
In the following example I want to have the command echo "You can't see me" in a variable and run it in such a way that the output ...
1
vote
1
answer
9k
views
dash: why am I getting the error "Syntax error: EOF in backquote substitution" when my script doesn't even contain a backquote?
#!/bin/sh --
for set_trap_sig in HUP INT QUIT ALRM TERM; do
trap -- '
trap -- - '"${set_trap_sig:?}"' EXIT || exit "$?"
kill -s '"${set_trap_sig:?}"' ...
2
votes
1
answer
8k
views
"cp: target '...’ is not a directory" during while loop
I have a directory of files whose names I want to shorten:
(3) andrew@andrew Learning_Plans $ ls -al
total 580
drwxr-xr-x 2 andrew andrew 4096 Apr 10 21:40 .
drwxr-xr-x 7 andrew andrew 4096 Apr 10 ...
0
votes
1
answer
1k
views
Construction an a command line bash script with spaces in path names [duplicate]
I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it.
In place of gcc for testing my script I've used:
#!/...
0
votes
2
answers
905
views
Quoting inside "sh -c" with double quotes
I'm trying to make this quoting work, but no success :
export perl_script='$| = 1;s/\n/\r/g if $_ =~ /^AV:/;s/Saving state/\nSaving state/'
mpv="command mpv"
mpvOptions='--geometry 0%:100%'
args=("$@"...
1
vote
1
answer
2k
views
Convert JSON with raw characters in string
Had a problem with a tool that was generating illegal JSON.
Some of the JSON strings contained characters in the range 00-1f. So I wanted to convert these characters to correctly escaped valued \...
6
votes
3
answers
9k
views
How to prevent parameter expansion around a variable I want to be resolved?
Edit:
Important note before reading further: since Kusalananda's anwser, my question is now quite useless, since he pointed out a bug in another script I used. Now this bug is fixed, the below errors ...
3
votes
0
answers
295
views
I can see but cannot delete a file [closed]
I am running Linux Mint.I tried to copy a file with the file manager. It looked like it hung.
I can see the file in the directory with ls -l:
-rwxr-xr-x 1 mike domain^users 20 Mar 1 08:57 'output (...
73
votes
1
answer
13k
views
What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?
Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used?
Do ...
1
vote
1
answer
59
views
I have a pipe separated file,read file row wise and search for unclosed quotes(") in each row and close that
Below is a row and i need to close "20 with "20"
2019-02-15T10:25:19+0100|ttt|werewrw|erewr|fddsfsdf|dfsdf|07|2ee7|1b65d04|"20|19|-02-|15t10:03|45435435|765767||SIP;rr=200;text="hyt"|
0
votes
3
answers
2k
views
Which quoting style GNU Bash variable definitions (mostly for paths)? [closed]
Which of the following quoting styles, for GNU Bash variables, is preferred and why?
Two double quotes: VAR="/path/$V1/path with space/$V2".
Multiple double quotes: VAR=/path/"$V1"/"path with space"/"...
25
votes
5
answers
4k
views
Why use double quotes in a [[ ]] test?
Let's say we have 2 integers in a bash script:
value1=5
value2=3
Then why do we need to use double quotes in case of a test ? For example:
if [[ "$value1" -eq "$value2" ]]
Why not just use the ...
2
votes
3
answers
941
views
Why can I not access a file named `-` even when quoting the filename? [duplicate]
I have a file called -. I want to display its contents.
One way is to do
cat ./-
since cat - reads from standard input.
However, why are cat "-" and cat '-' also interpreted by the shell ...
6
votes
1
answer
5k
views
Why does scp's strict filename checking reject quoted last component but not others?
When I try to scp a file with a slash in its path, the path is quoted for the local host, and the last path component is additionally quoted for the remote host, like scp host:"a/b/'c'" ., it fails ...
-1
votes
1
answer
111
views
Why did Debian use the typewriter apostrophe (') instead of the closed curve quote (’) [closed]
I have been using Debian for quite a few years. Every now and then, when I write or read something I find it confusing what an author meant by it. I had a look at the wikipedia page, as well as this ...
5
votes
3
answers
26k
views
Kill remote process via ssh
I have a process that I want to kill remotely. I tried
ssh remotehost "kill -9 $(ps -aux | grep foo | grep bar | awk '{print $2}')"
but this returns the error
kill: usage: kill [-s sigspec | -n ...