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
0
votes
2answers
54 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 ...
10
votes
1answer
5k views

rsync exclude-from directory with space

I am trying to exclude "Mendeley Desktop" directory for rsync. The exclude-from= is as: Downloads *.o *.iso Dropbox Documents/Mendeley\ Desktop but rsync is still backing up the Mendeley Desktop. ...
1
vote
1answer
61 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 ...
-2
votes
2answers
74 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 ...
0
votes
1answer
14 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
1answer
10k views

passing string containing spaces as command-line argument from within script

I'm using a bash shell on mac. I want to write a shell script 'gac' such that running > gac one two three produces exactly the same effect as running > git add . > git commit -m "one two ...
1
vote
2answers
38 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 ...
1
vote
1answer
55 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
2answers
72 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 ...
2
votes
1answer
64 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
2answers
188 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
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 ...
6
votes
3answers
975 views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[@...
203
votes
3answers
17k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
4
votes
2answers
173 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 ...
1
vote
1answer
45 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
1answer
25 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/...
19
votes
1answer
4k views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: s/cid:image002\.gif@01CC3D46\.926E77E0/https:\/\/...
3
votes
2answers
2k views

How do I eval two commands?

If I run this: echo "echo 'a'; echo 'b'" It produces a string which I can then run, and it works - echoes a\nb\n. However, this does not work: $(echo "echo 'a'; echo 'b'") Why not? It doesn't ...
0
votes
2answers
85 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)
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
151 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. ...
2
votes
1answer
50 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'...
2
votes
1answer
80 views

How to get a list to be entered in quotes

I have a script that runs a python script (used to deduplicate emails via IMAP) after a user has entered a servername, username & password. The first part of it gets a list of folders which the ...
0
votes
0answers
29 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 ...
25
votes
3answers
14k 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? Thanks. $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my':...
0
votes
1answer
55 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 ...
108
votes
6answers
86k views

How can I execute `date` inside of a cron tab job?

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
3
votes
1answer
262 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 "$?"' "$...
3
votes
2answers
1k views

OpenSSH: Prevent globbing on SSH_ORIGINAL_COMMAND

I have the following setup where I use an OpenSSH server to remotely start a certain command using ssh. My authorized_keys file has the following entry: command="/path/to/script.sh $...
1
vote
1answer
100 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: backup-20151219....
6
votes
4answers
1k views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' I need to construct an example where the first form fails but the second still works.
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 ...
12
votes
2answers
53k views

How to use a special character as a normal one?

Many questions like 'How to type the double-quote char (")?' are being asked, and we don't want to clutter our community with the same answer (Type it as \" if not enclosed in 's, " if enclosed in 's.)...
595
votes
13answers
1.4m views

How do I grep for multiple patterns with pattern having a pipe character?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
2
votes
1answer
279 views

cp not evaluating dirname properly in find operation [duplicate]

I'm trying to create a script which will find files of a certain filename, copy a file to that file's location, and then delete the found file. Ignoring the delete part for now, this is what I have ...
2
votes
1answer
153 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
53 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=("$@"...
180
votes
3answers
27k views

Why is 'ls' suddenly wrapping items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them ...
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 ...
1
vote
1answer
64 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 \...
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 '....
58
votes
5answers
84k views

Pass shell variable as a /pattern/ to awk

Having the following in one of my shell functions: function _process () { awk -v l="$line" ' BEGIN {p=0} /'"$1"'/ {p=1} END{ if(p) print l >> "outfile.txt" } ' } , so when called as ...
2
votes
3answers
944 views

How do I invoke jq inside awk?

Essentially I have a file.log as follow blah blah blah blah Hello world | {"foo": "bar"} blah blah Hello earth | {"foo1": "bar1"} Now my goal is to write some shell commands to have desire output ...
2
votes
5answers
7k views

Get process elapsed time in seconds

Similar to How to check how long a process has been running?, I am trying to get the elapsed time for a process in seconds in an embedded Linux system using BusyBox and sh (not bash). The difference ...
1
vote
1answer
3k views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
1
vote
1answer
62 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 ...
2
votes
2answers
550 views

bash: can't set a variable to a solid string [duplicate]

I cannot set a variable with a whole command-string as following: A="/bin/ps wwwaux" for a in $A do echo "$a" done It assigns array instead of solid string someway. My environment: GNU/Linux, ...
66
votes
8answers
23k views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...