Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [quoting]

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

2
votes
1answer
56 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
1answer
2k 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 ...
4
votes
2answers
165 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
1answer
23 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
1answer
41 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
2answers
76 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)
2
votes
1answer
43 views

Why I have to not quote a string variable in this specific case?

My Ubuntu/Debian-based Linux update POSIX shell script seems to require me not to double quote the string variable with the stored command, which is being executed. As I don't understand this issue, I'...
0
votes
0answers
26 views

Why does single quotes around arguments fail to prevent “syntax error near unexpected token '('”? [duplicate]

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following ...
2
votes
4answers
104 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
1answer
54 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 ...
3
votes
1answer
200 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:?}"' -- "$$" || exit "$?"' "$...
2
votes
1answer
81 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
1answer
28 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
2answers
44 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
1answer
49 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 \...
0
votes
3answers
217 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
0answers
55 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 (...
0
votes
0answers
16 views

How do you escape “-” in a command in the Shell (Zsh)? [duplicate]

I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following mv \-a "a" mv '\-a' "a" mv "\-a" "a" but got mv: illegal option -- a usage: mv [-f | -...
44
votes
1answer
3k views

What is the difference between “…”, '…', $'…', and $“…” quotes?

Sometimes I see scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do they behave differently ...
1
vote
1answer
39 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
3answers
62 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"/"...
23
votes
5answers
2k 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
3answers
643 views

Why can I not access a file named `-` when quoting? [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 as cat -?
6
votes
1answer
460 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
1answer
49 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 ...
0
votes
1answer
498 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 ...
3
votes
1answer
71 views

Commands Differences Using Quotations (Find)

I was reading the man page of find and I found myself confused with the following commands. What is the difference between one and its corresponding one. What is the difference between the following ...
0
votes
2answers
86 views

Is the behavior of escaping special characters inside double-quotes in mainstream POSIX-compliant shells at odds with POSIX?

Per the POSIX Shell Command Language Page: \ The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
3
votes
3answers
157 views

POSIX Shell: inside of double-quotes, are there cases where `\` fails to escape `$`, ```, `"`, `\` or `<newline>`?

Per the POSIX Shell Command Language Page: \ The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
1
vote
1answer
52 views

Prevent quote expansion in user-made function [duplicate]

I have the following bash function : tg() { git add -A && git commit -m $1 && git push } But it seems not to work : $ tg "create index for users" error: pathspec 'index' did not ...
0
votes
0answers
13 views

Interaction of sed and for loop [duplicate]

for i in {1..25}; do cat file$((i)) | sed 's/.*/$((i))/'; done doesn't print the current value of i but just $((i)). How can I make it print the value of i instead?
9
votes
2answers
397 views

How to create alias with a command contains ' and "

A few posts ago someone asked how to show memory in percentage. Someone replied with: free | awk '/^Mem/ { printf("free: %.2f %\n", $4/$2 * 100.0) }' I was wondering if I can turn this command into ...
0
votes
1answer
56 views

Can I put a single quote in a user's password

I was wondering if there would be any issue with placing a single quote in a ubuntu user's password. We have a couple machines with a dummy user for automation purposes and I would like the password ...
1
vote
1answer
452 views

Cannot rm or cp files with a wildcard in name [duplicate]

I have a line like this in my script: rm "$TEMP_DIR/*.txt" It fails with this output: rm: cannot remove 'temp/*.txt': No such file or directory I don't understand why doesn't that work. What am I ...
-5
votes
2answers
77 views

Does process substitution need to be double quoted?

Double quoting command substitution is a good practice. Is it the same for process substitution (<() and >())? It seems double quotes allow command substitution, but disallow process ...
-2
votes
1answer
71 views

Shell script with password that starts with ( [closed]

I have a shell script that opens ftp, then passes on the user ID and password. The password starts with ( and the server does not like it. It errors outs with a failure to log in message. How can I ...
0
votes
3answers
216 views

Why does double quoting an array expansion in here document not seem to work here?

I have two arrays $ arr1=( 1 2 2 3) $ arr2=( 2 3 3 4) Why does this generate strange output when I follow the good practice of double quoting an array expansion $ tsort << EOF > "${arr1[@]}...
-2
votes
1answer
306 views

Quotes don't work anymore with: git commit -m “My commit message” [closed]

I am not sure what is going wrong (terminal, shell, system?), but when I enter: git commit -m "My commit message" this morning, I get: error: pathspec 'My' did not match any file(s) known to git ...
0
votes
1answer
44 views

complicated command replace in files using sed [duplicate]

I want to replace the below strings replace: print 'Status Code: {code}'.format(code=r.status_code) with: print('Status Code: {code}'.format(code=r.status_code)) Here is the command I ran which ...
-2
votes
2answers
37 views

Handling whitespace in filepaths

I have this: muh_dir=`cd $(dirname "$BASH_SOURCE") && pwd` and yeah I tested the above (it has backticks) and it doesn't work well with whitespace in the pwd. On the other hand, this is ...
1
vote
3answers
121 views

SSH with Command Doesn't Run as an Alias

I have the following command to remote into a local server and tail -f the latest log file for an application that I have. The command works perfectly fine from the command line - ssh user@hostname ...
3
votes
1answer
674 views

What's the different between with a ~ and without a ~ in a string variable in Bash? [duplicate]

I'm using a dotfile manage software, named dotdrop. Using a config file named .env, contents like: git_folder="~/code/Git". Also use a script to setup this dotfile tool before the first use of it, as ...
2
votes
3answers
994 views

Bash Script to remotely collect hostname, IP and host total memory

I am trying to write a scrip that will collect the hostname, IP and total memory installed on remote hosts from a list I feed into the script. The script will collect information from Redhat and ...
0
votes
4answers
1k views

get output of this command from another server via ssh

I'm trying to ssh into a server and get the system uptime using a specific command but it's failing to execute. this would work locally on almost all unix systems startuptime=`uptime | awk '{print $...
1
vote
2answers
39 views

Using rsync to delete selected patterns, matches all files

I mean to use rsync to remove certain files (for Efficiently delete large directory containing thousands of files), in this case given to a shell script as patterns in the command line. So far, this ...
0
votes
0answers
15 views

How to append a “/*” to the end of a variable with spaces and glob it? [duplicate]

If I have a directory wibble, the following command does what I want: WIBBLE=wibble wc $WIBBLE/* If I have a directory foo bar, the following command does what I want: wc foo\ bar/* But this doesn'...
2
votes
1answer
310 views

Escaping problem with find command

I need to find everything in a directory, excluding certain subdirectories and files. My script needs to call this as a function: function findStuff() { # define exclusions ignore_dirs=("$1" "*...
0
votes
0answers
26 views

Quoting of SQL excuted via psql via ssh

I want to execute this SQL line: select * from "foo" where name='bar' I call above line "sql_line" in the next statements. Now I want to call this via psql: psql -c sql_line Now I want to call ...
0
votes
1answer
56 views

Using a bash loop to run a program that uses single-quotes in the command line, where single-quotes nullify the bash script's intention

The problem: I want to be able to run a program within a bash loop over each .fna file in a directory, but I also want the name of the output file to have the same file name (without the extension), ...
2
votes
1answer
116 views

Shell command executed differently in a terminal and script

The following sequence of commands ch=`echo "b_d" | sed 's/_/\\\\\\\\_/'` echo $ch when executed in a terminal or via source give an output b\\_d When ran as a scipt sh script.sh where the ...