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
1
vote
2answers
44 views

How can I parameterise my command in a bash script file?

Edit -- Not using bash $1 variables. Example is using field designators: $1, $2, $3 are the awk input record fields Unfortunately I did the example too quickly and mixed-up the example. I believe ...
0
votes
1answer
48 views

Backticks evaluation problem in quoted command, in su -c, in heredoc, fed into 2 layers of ssh

I have the following chain of indirection: ssh -t root@host1 ssh host2 << EOF\nsu - user2 -c 'kill `cat ~/file_with_pid`'\nEOF In the end what I need is just to kill a process (reading the pid ...
3
votes
2answers
55 views

Globbing within a parameter expansion

I'm trying to select the files within a set of directories passed as arguments with the following: ${@/%/*} However, this is not ideal, since paths with spaces will break, and quoting the parameter ...
0
votes
1answer
65 views

Quoting a command line argument containing a variable that may have both single and double quotes in its expansion

After some unsuccesful attempts at quoting the command string correctly, I ended up using the below command to run the identify command on the .jpg files under the working directory, the names of ...
3
votes
3answers
103 views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
0
votes
3answers
64 views

echoing Command to cron.d

I am trying to append/echo a command to cron.d. However, when running the script that echoes the command: echo */2 * * * * /usr/bin/aws ssm-send-command --document-name "AWS-RunShellScript" --...
0
votes
2answers
44 views

Utility to add quotes to argument

I have an issue which can be solved with utility to add quotes to argument and output to standard. I did a web seach for "linux utility to add quotes to argument" and found nothing relevant. Is there ...
2
votes
1answer
66 views

Single quote problem in “sh -c” script launched from “find”

Now I am writing a script for a long time, but lately this problem has drives me crazy. I tried everything but couldn't solve it. find . -iname "*.mp4" -type f -exec ffmpeg -i "{}" -c:a "$ACODEC" -c:...
1
vote
1answer
205 views

Replacing '\'' with sed

I want to replace '\'' in a text file to another word or character using sed command. Tried using sed "s/'\''/×/g" but it doesn't work. Anyone know the solution?
0
votes
1answer
147 views

I received error “bash: line 1: [: -ne: unary operator expected” after run the below script

This script provides the expected output, but throw the error "bash: line 1: [: -ne: unary operator expected". Techies help to fix this. #!/bin/bash USR="root" # Email SUBJECT="NTP Service Status ...
1
vote
1answer
75 views

problem escaping quotes in script

I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this : mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
-1
votes
1answer
34 views

Bash ANSI C quoting not correctly quoting newlines

ANSI C Quoting in bash is supposed to read strings the same way C(or python with single quotes) would. printf $'"Hello, World!\\n"' #expected output (no newline, the slash is escaped) "Hello, World!...
2
votes
2answers
64 views

What is the right way to quote nested parameter expansions?

When dealing with with nested parameter expansions, which of these is the correct way to quote things? This one: var="${var#"${var%%[![:space:]]*}"}" Or this one: var="${var#${var%%[![:space:]]*}}"...
0
votes
1answer
47 views

Quote a special character in a script file using awk

So I'm looking to write a script file which takes in a user-inputed number, and based off that number, it will execute a certain command. This command is the awk command that, of course, uses a field ...
0
votes
1answer
87 views

how to use quotes in sed & ssh?

i cant get this to work in bash/rhel 7: ssh host "sed -i -e \"s/dnl MASQUERADE_AS.*\$/MASQUERADE_AS(\`domain.com\')dnl/\" /etc/mail/sendmail.mc" bash: -c: line 0: unexpected EOF while looking for ...
0
votes
1answer
57 views

Why do these rsync filter args fail in bash when passed in array?

Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}"...
4
votes
2answers
442 views

Is there a way to printf $@ verbatim?

I want to write a script that echoes to stdout its $@ verbatim, including any potential double-quotes, without a newline. What I have tried: > cat ./script1 #! /usr/bin/bash printf "%s %s" $0 ...
0
votes
2answers
75 views

How can I pipe sed output to printf for formating?

I am using Tecplot to process wind tunnel data, but the input for Tecplot requires a specific format for variable specification; each variable is bracketed by double quotes "Variable Name". The ...
3
votes
1answer
155 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 ...
1
vote
2answers
241 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
1answer
76 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
2answers
64 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
1answer
207 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
1answer
257 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 ...
1
vote
2answers
338 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
1answer
40 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
1answer
42 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
1answer
54 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
3answers
49 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
1answer
35 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 -...
-1
votes
2answers
56 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
1answer
29 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 ...
-1
votes
1answer
38 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 ...
0
votes
2answers
420 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 ...
2
votes
4answers
887 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
0answers
51 views

CSV fields max length error and setting quoting=csv.QUOTE_NONE

After running csvcut on a comma-delimited .csv file (downloadable here): [root@server files]# csvcut -c title,mpn,overview,techspecs2,image_carousel_elargesrc syn_multi-image.csv > syn_scraped_cut....
1
vote
0answers
32 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
2answers
89 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 ...
1
vote
1answer
721 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 ...
0
votes
1answer
89 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
2answers
62 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
2answers
320 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
1answer
320 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
467 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
126 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
238 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
30 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
75 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
302 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)

1
2 3 4 5
19