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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [quoting]

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

2
votes
1answer
36 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
26 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
38 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
35 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
81 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
53 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
37 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
53 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
640 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 -?
5
votes
1answer
343 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
48 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
153 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
69 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
83 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
118 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
49 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
389 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
49 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
223 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
71 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
65 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
176 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
221 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
42 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
36 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
112 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
673 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
628 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
750 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
36 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
256 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
25 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
44 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
91 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 ...
2
votes
1answer
175 views

Bash: Allow parentheses in command arguments (i.e. prevent “unexpected token '(' ”)

I am frequently using a command line program that I provide with arguments that contain parentheses. For simplicity, let's say I'm writing echo 'bar(1,3)' I would like to omit the quotes. However, ...
0
votes
2answers
66 views

Setting an alias when double quotes and single quotes both fail

This question is not a duplicate of Why alias behave different than running bash command directly? because I have tried that solution and it hasn't worked. I replaced all my single quotes with double ...
2
votes
1answer
38 views

Generating quoted command arguments

I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general. So, I've written a small script that, ...
3
votes
2answers
1k views

How to delete or access a file with a backslash \ in its name?

I have some files here that I copied over to this linux box using the python module pysftp: [jm@spartan tf]$ ls -la total 0 drwxrwxrwx. 3 jm jm 69 Aug 14 13:50 . drwxrwxrwt. 9 root root 238 ...
0
votes
2answers
91 views

Keeping quotes passed to a perl wrapper script

I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name. ./foo.pl -a one -b two -c "1 2 3" -d done When I output @ARGV, the "" around 1 2 3 have ...
0
votes
2answers
35 views

Bash : Give builded array to function as a list of argument?

I have this issue with borgbackup, but because the reaction is the same, I will use rsync in my example. I want to build an array of arguments by adding a prefix to each, and then give that array to ...
2
votes
2answers
148 views

Index range of array doesn't allow you to iterate over a new line in bash

I'm working on a simple bash script that fixes a duplicate naming issue on a retropie. The script itself grabs any name that is mentioned more than once in a gameslist.xml file, then stores those in ...
0
votes
1answer
47 views

unable to include inverted comma's while using an echo comand

I was trying to echo the SNMP configuration inside the /etc/snmp/snmpd.conf file, however, i noticed that it is removing "" while echoing the text inside the configuration file..... i have tried out ...
1
vote
1answer
43 views

Is arithmetic expansion related to IFS in some way?

From https://unix.stackexchange.com/a/458074/674 arithmetic expansions are also subject to split+glob so should also be quoted (shift "$((OPTIND - 1))") (here not a problem though as you're using ...
-1
votes
1answer
1k views

Unexpected EOF while looking for matching ``' Ex01 [closed]

I have a BASH project and I face two errors that I do not understand. Here is my BASH script: #!/bin/bash proc_name=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f1 | uniq`; ...
1
vote
1answer
47 views

Loop that lists folders with spaces

Approach I have a directory with named folders, randomly, with blank spaces and periods. I created a small loop (in a script) with the intention of renaming these folders. On the basis that these ...