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
10
votes
2answers
414 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
107 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
756 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 ...
-4
votes
2answers
83 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
80 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
313 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
382 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
46 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
39 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
130 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
1k 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
2k 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
48 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
400 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
27 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
73 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), ...
3
votes
1answer
234 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
462 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, ...
1
vote
2answers
111 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
42 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
161 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
39 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
283 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
116 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
48 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
2k 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
51 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 ...
1
vote
1answer
63 views

variable `-name` primary to `find`

I am trying to construct a compound -name primary for the find command from an arbitrary number of strings in an array, of the form \( -name ${a[0]} -or -name ${a[1]} -or -name ${a[2]} ... \). While ...
2
votes
2answers
9k views

How do I grep multiple patterns from a pipe

I want to find three patterns in a list. I tried typing $ pip3 list | grep -ei foo -ei bar -ei baz but the shell throws a broken pipe error and a large Traceback. How do I grep for multiple ...
0
votes
2answers
752 views

Bash - variable contains dollar signs

I have a php script that passes a variable to a bash script: exec("bash.sh $path") The bash script looks like so: #!/bin/bash path=$1 echo $path If the path ends in dollar signs like so: myfile.$$...
2
votes
3answers
432 views

Printf fails to intepret backslash and exclamation mark

I am writing a java program from terminal using printf and redirecting its output to a .java file but printf fails to interpret the horizontal backslash tab (\t), and when I have an exclamation mark (!...
1
vote
1answer
133 views

Aliased an awk command successfully now won't use OFS [closed]

So I was able to get a command finally with the ability to get and grep the information from a specific file I wanted and then I ran into a problem with alias: find ./ -type f -name filename.ext -...
1
vote
3answers
278 views

Escaping double quotes in dynamic rsync command

I am building a script that should duplicate the current users home directory to an arbitrarily selected directory, linking to the most recently created duplicate in the same directory, if any, using ...
3
votes
2answers
879 views

Correctly escaping quotation marks

I have the following command: python -c 'import crypt; print(crypt.crypt("$Password", crypt.mksalt(crypt.METHOD_SHA512)))' Where $Password is a shell variable. How do I correctly expand it as a ...
1
vote
0answers
47 views

Is there any point in quoting simple strings? [duplicate]

Is there any reason for doing something like: a="abc" or a='abc' The quotes seem completely superfluous, but then there might be some hideous corner case... I'm interested in Bash and Sh in ...
0
votes
1answer
46 views

bash4: cp command cannot see files when enclosing file path inside a double quote

consider the following terminal output (inside a .sh file) kagura@mylaptop1 : ~ => sudo cp -a "$_source/*.txt" $_destination/Other/ Password: cp: /home/myuser/*.txt: No such file or directory 08:...
0
votes
1answer
511 views

Interpolate within single quotes

I have the following: COMMENT="A random comment" TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}' echo "$TEXT_JSON" | jq . This prints { "person": "Jim", "comment": "$...
10
votes
2answers
465 views

Why does `sudo -i` but not `sudo` remove newline characters? [duplicate]

What can explain the examples below and how do I fix this, preferably without heavy quoting acrobatics? I am using the $n to simulate multiple line command strings, just in case it distracts you from ...
1
vote
0answers
2k views

Why use a variable in a bash regex match inside [[? [duplicate]

There is not a simple answer to this question at this site yet. This question aims to give a simple and clear answer. It is usually recommended to use a variable ($regex) in this construct: if [[ $...
6
votes
1answer
1k views

Using a variable as a case condition in zsh

My question is the zsh equivalent of the question asked here: How can I use a variable as a case condition? I would like to use a variable for the condition of a case statement in zsh. For example: ...
7
votes
2answers
2k views

ls with a wildcard

This works from the terminal: ls /dev/sda* I want it in a bash script, using a variable. I tried: device="a" ls "/dev/sd"$device"*" But I get the error: ls: cannot access '/dev/sda*': No such file ...
1
vote
1answer
64 views

cd to a path containing spaces using a path variable [duplicate]

I have a file containing a list of commands which I run from my .bash_profile as source my_cmds For eg: $cat my_cmds scripts=~/scripts assuming my $HOME is /Users/knayak, when I run cd $scripts ...
6
votes
4answers
2k views

shell: Quote string with single quotes rather than backslashes

How can I quote a string with single quotes? Eg, I can do: $ printf "%q\n" 'two words' two\ words $ Is there a way to get a single- (or double-) quoted string as output, ie: $ MAGIC 'two words' '...
1
vote
1answer
79 views

Why is there a different behavior for quoted parameters when in crontab?

Case scenario: $ echo "1,2,4" | grep -v [0-9] [No results, as expected] But, when doing it via cron: $ crontab -l [...] * * * * * echo "1,2,4" | grep -v [0-9] > /tmp/debug.dump [...] $ cat debug....
0
votes
2answers
61 views

Should history expansion be quoted?

I've just come across !$ (without quotes). I've not met this before and did some tests: $ ls -l (...some output...) $ echo !$ -l $ echo "!$" -l man bash says this in the section on history expansion:...
30
votes
3answers
19k views

How can we run a command stored in a variable?

$ ls -l /tmp/test/my\ dir/ total 0 I was wondering why the following ways to run the above command fail or succeed? $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my': No ...
1
vote
0answers
650 views

Hmac with openssl's command line tool with a key that might contain null bytes

Let's say I want to do an SHA256HMAC digest of a file with the openssl command line utility: openssl dgst -sha256 -hmac "$(cat $KEY_FILE)" -hex "$TARGET_FILE" How can I protect this command against ...