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
1answer
62 views

Put quotes around strings between commas, but not numbers

So I have some text in a file that almost represents CSV format, but not entirely. I want to turn in into a CSV file though. I have for example: cuz,0,1,2,3,-4,abc,a b c,0 How can I turn that into ...
1
vote
1answer
132 views

Bash - why I can execute command string with pipelines only through “bash -c”?

Code example below shows the problem: bash -c "$(echo 'ls | wc -l')" # Working "$(echo 'ls | wc -l')" # Not working $(echo 'ls | wc -l') # Not working 'ls | wc -l' ...
1
vote
2answers
543 views

Use sed command with variables

I have tried every possible solution available on the Stack Overflow and its related websites but did not find any solution. I spent a reasonable amount of time on this issue and am finally posting ...
1
vote
1answer
278 views

How to pipe netcat's output? Problems with xargs and quotes

I'm trying to pipe whatever nc receives with this: nc -l 20000 | xargs /root/test ...and it works fine, except when xargs receives quoted arguments - it splits them as if they were separate... ...
2
votes
2answers
3k views

How to copy files using scp from remote host when file have spaces

I need to copy a file from remote host to my local directory using scm where a file have spaces, for not I fixed the issue by ssh to that host and scp the file back. But I want to know how to copy ...
0
votes
1answer
489 views

Date command is not working in remote server when running using a script

I am running below command from a script from a remote server, but getting error No such file or directory ssh -t -t user@xx.xx.xx.xx \"sudo mysql nss_mysql < /home/user/scripts/Db_nss_mysql-`date ...
0
votes
2answers
68 views

Centos gawk command line usage

I am trying to run the following command on Centos however I get an error? Unexpected token near '(' gawk { if($0=="id323"){print $0} } doc.txt
0
votes
1answer
91 views

wget outputs 3-byte quotation marks

I ran a wget -b. From the log, I was trying to get the list of files successfully downloaded, and for that I did a grep saved wget-log | awk -F '"' '{print $2}' but it didn't work. Further ...
3
votes
1answer
2k views

How to include a colon in specific command sudoers entry?

I need to add an entry to the sudoers file to allow the user to run a specific command. So it happens the command includes a colon " : " mount -t nfs -o vers=4 host:/remoteMountpoint /home/username/...
0
votes
1answer
948 views

Print a variable in single quote on bash | Weird Variables

On bash script, I need to pass date as ansible extra variable but getting something single quotes related issues; ... $DT="03-04-17" ansible-playbook copy2s3.yml --extra-vars 'cdate={{ "$DT" }}' and ...
3
votes
1answer
482 views

bash add value to array with embedded variable and single quotes

I'm sure it's completely clear from the subject :) Joking aside, I think part of the problem I'm having finding an answer is writing the search terms. I have had good luck when issuing commands in a ...
7
votes
1answer
9k views

Printing epoch time with the date utility

From reading another answer I know the following command can be used to print the current epoch time: $ date +'%s' 1491150773 From reading through the date(1) man page (note: I actually use macOS) I ...
5
votes
2answers
484 views

How to re-write this function to avoid argument injection

I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh. Currently, the function contains: function runMyScript { if [ $1 = "s3" ] then ...
2
votes
1answer
240 views

Redirecting a Makefile inside a cat heredocument vanishing variables and line breakes

Executing: cat <<MAKE >> /etc/apache2/sites-available/Makefile1 % : printf '%s\n' \ '<VirtualHost *:80>' \ 'DocumentRoot "/var/www/html/$@">' \ 'ServerName $@' \ ...
2
votes
2answers
135 views

How to protect expressions in the 'find' command from interpretation by the shell?

I would like to run the command find . '! -name *.*' in the bash shell. It does not work as intended. (It should list all files in the current directory for which -name *.* is false, i.e. which do not ...
2
votes
2answers
82 views

shell command 'var=“[a-p]”; echo $var' has as output “h”, any explanation? [duplicate]

bash version: $ bash -version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu....
0
votes
1answer
726 views

mask Dollar, brackets and quotes in remote ssh command [duplicate]

I want to do some script on a remote mashine through ssh: ssh Server "V=\$\(lua -e 'print\(require\(\\\"platform_info\\\"\).get_image_name\(\)\)'\); echo \$V" But this echo $V at the end gives me ...
0
votes
3answers
536 views

issue with back quotes inside while loop when running a command over ssh

This question is a bit complicated. I will try to explain in detail. I have two machines, one is local and other say 192.168.1.2. I have set the following variables in my local machine CHECK="/home/...
5
votes
3answers
4k views

Spaces for variables in bash script

I have a space in one of the directory names. I want to list a file under it from a bash script. Here is my script: fpath="${HOME}/\"New Folder\"/foobar.txt" echo "fpath=(${fpath})" #fpath="${HOME}/$...
8
votes
1answer
770 views

Why doesn't GNU parallel work with “bash -c”?

% echo -e '1\n2' | parallel "bash -c 'echo :\$1' '' {}" :1 :2 % echo -e '1\n2' | parallel bash -c 'echo :\$1' '' {} % I'd expect the second line to act the same.
1
vote
3answers
5k views

Echo new line and string beginning \t

Sure, echo -e can be used so that \n is understood as a new line. The problem is when I want to echo something beginning with \t e.g. "\test". So let's say I want to perform echo -e "test\n\\test". I ...
4
votes
1answer
556 views

readlink literal vs variable

Using BASH: the answer is probably obvious but, not for me. > echo $PWD /root/fcm > readlink -f ~ /root > # but then with a variable or literal > a='~' > readlink -f $a /root/fcm/~ >...
0
votes
1answer
1k views

Why does \n expand to n in bash?

When it comes to the shell operation, I can understand the step one, but the second step a little puzzles me. Here is my understanding: First, shell splits input into words and operators, then ...
9
votes
1answer
16k views

What characters need to be escaped in files without quotes?

I have browser-based shell/terminal that executes bash commands and I'm escaping spaces but it turns out that parenthesis also need to be escaped. What other characters need to be escaped for file ...
0
votes
2answers
2k views

Why do we double-quote a dollar sign evaluation in Bash? [duplicate]

I know single quotes will not evaluate what's inside, and double quotes will. I often see people quote-quote the dollar sign evaluation. Here are some examples: for i in "${indices[@]}"; do if [ "${a}...
4
votes
4answers
4k views

Backslash usage in different commands

I have been trying to get a better understanding of how backslash is used in certain commands. I understand its usage for escaping special characters (Such as echo 'that'\''s no moon' ), but the ...
0
votes
2answers
55 views

chmod files with group - error on files with (

I have the need to chmod files which are in a certain group. I have come up with this construct: find . -group groupname -exec sh -c 'su -c "chmod -R u+w,g-w,o-w,g+r,o+r ." - groupname {}' \; This ...
0
votes
2answers
48 views

In what way does quoting parameters to `find` matter? [duplicate]

When looking for txt files, I run this command: find . -name "*.txt" -print This gives me a list of all the text files beneath current directory. However, find . -name *.txt -print gives me the ...
0
votes
1answer
124 views

Bash variable quoting in a function

I've defined a short helper function in a bash script. For legibility, I'd like to replace the boilerplate headers with a variable declared outside the function. I've tried quoting the declaration ...
0
votes
1answer
6k views

Howto use $ variable inside single & double quote command

I have a bash script with following: USERLIST="/tmp/adusers.list.names.only.txt" cat $USERLIST | while read users do num=$[$num+1] USR=`echo $users | awk '{print $1}'` STATUS=`winexe -U DC/ID%"PASS" /...
9
votes
3answers
1k views

What's the difference betwen " and ' - and when to use it? [duplicate]

I'm used to type strings with quotation marks, but from now and then when I surf through config files and recommendations, I see apostrophes being used. I often copy apostrophe things into my config ...
1
vote
1answer
1k views

find -exec not working in bash script but working in terminal [duplicate]

I am trying to write some bash script to replace a command I quite often use. Here is the code from my file test.sh #!/bin/bash echo -e "\n" i=0 args[i++]=$0 for arg in $@ ; do args[i++]=$arg done ...
0
votes
1answer
122 views

Alias and syntax error [duplicate]

The following terminal command will print the output of any other command in a slow fashion. <any command> | awk '{system("sleep .2");print}' I often like to use this and I want to create an ...
1
vote
3answers
2k views

bash - Single quotes being added to double quotes [closed]

I'm writing a script to run a given program on a simulator while changing the argument supplied and I'm having a problem where bash keeps inserting single ticks around the double quotes that causes ...
5
votes
1answer
188 views

Why file glob expansion is not suppressed

I have the following script my.sh: echo $@ Now I want to see file glob expansion, so I do like this and it works OK: $ bash my.sh * $ f1 f2 my.sh Now, I've tried suppress expansion using ...
2
votes
0answers
136 views

How to explicitly set the tabname of a new gnome-terminal?

I want to explicity rename a tab in gnome-terminal on startup of the tab. I don't want to use gnome-terminal --title flag as that gets reset by my systems bashrc file after whatever else is supposed ...
2
votes
1answer
661 views

How to pass a list of variables into sed in a shell function

I want to append multiple variables to the end of a line that contains a certain string. Here is my function: function () { sudo sed -i '/^STRING/ s/$/ '$@'/' FILE; } However I got sed: -e ...
6
votes
1answer
594 views

Does bash have different weak quoting rules for special variables?

I don't think I fully understand the nuances of quoting in bash. I have a script, foo.sh, which simply outputs numbered arguments. #!/bin/bash i=1 while [ $i -le $# ] ; do v=$(eval "echo \$$i") ...
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 ...
9
votes
2answers
2k views

How to stop .bashrc from running sub-command in alias at startup? [duplicate]

I have added an alias command to kill my guake terminal to my .bashrc alias killguake="kill -9 $(ps aux | grep guake | head -n -1 | awk '{print $2}')" But the problem is, the sub-command i.e. ps aux ...
1
vote
2answers
2k views

How to escape quotes in shell within both usage of ssh and sudo?

In one word: question and example could test locally: sh -c "echo 'how to print single quote here'" details: I have a config like this: upload_server = ('192.168.1.1', 10051) now I need a shell ...
0
votes
3answers
632 views

“bash: !/bin/su”: event not found" [duplicate]

I have line in script which is working, but not working from command line. echo "User ALL = NOPASSWD: ALL, !/bin/su" | sudo tee -a /etc/sudoers [user@localhost ~]$ echo "test ALL = NOPASSWD: ALL, !/...
0
votes
1answer
191 views

\1 in sed command not working under xonsh

I don't understand what I'm missing here: $ echo 'testing' | sed -E 's/([a-z]*)ing/\1ing/g' ing I would expect the output to be testing again, since \1 should be test? That input seems to have been ...
0
votes
1answer
580 views

How to launch Notepad++ from the Cygwin command line via an alias?

This is what I tried. $ alias n++='(cd `dirname $1`; "/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe" `basename $1`)' alias n++='(cd `dirname $1`; "/cygdrive/c/Program Files (x86)/Notepad++/...
1
vote
1answer
43 views

how to add command with new line in the variables? [duplicate]

as you know when we writing list=$(ls -l) all the files added to $list like this : total 0 drwx------ 7 mine-pc staff 238 Dec 22 11:32 Applications drwxr-xr-x@ 6 mine-pc staff 204 Jan 11 11:00 ...
0
votes
3answers
7k views

How to add a line break inside a bash string? [duplicate]

I have the following bash string and I need to add a line break to it, before the 'Hello' string: bash -c "echo 'Hello' > /location/file" I already tried adding it with different variations of ...
0
votes
1answer
57 views

Why does `cd ~“/mydata”` succeed while `cd ~/“mydata”` not

Why does the first command fail, while the second succeeds? $ cd ~"/mydata" bash: cd: ~/mydata: No such file or directory $ cd ~/"mydata"
1
vote
3answers
354 views

Why doesn't grep return what I expect when I use single quotes

I have a file with the below contents: sh-4.2$ cat file1 example of multiple pattern this is an example of multipole sorry multiple pattern matching using grep so the example is the file itself -...
0
votes
2answers
1k views

Is it possible to not escape double quotes and get the right json format?

I want to submit json data using httpie. If I use double quotes and escape the double quotes surrounding the key, it works. json="[ \ { \ \"count\": 3 \ } \ ]" echo $json [ { "...
4
votes
3answers
4k views

Problem with passing a variable to sed

I know that when passing a variable to sed, one should use double quote. So when I was using sed to display a line of a file given a line number: sed '894!d' cloud.cpp It works, but since I also ...