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

learn more… | top users | synonyms

1
vote
3answers
220 views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
0
votes
1answer
72 views

Could not get a command to work with bash -c

I am trying to execute a command to find out which process is listening on a particular port and i cannot get it to work if the command is passed as an argument to bash using bash -c netstat -tnlp ...
1
vote
1answer
145 views

Cat write text with “$” inside

I want to write configuration information to a specific file which has dollar signs ($) inside. That seems to be a problem. Here's what I did: $ cat >> /etc/nginx/nginx.conf <<EOF # For ...
1
vote
2answers
76 views

double-quoting parameter (representing filename) doesn't help if spaces are contained

When iterating over some filenames double-quoting the parameter does not prevent the filename from being broken: $ mkdir temp $ cd temp/ $ touch a\ b $ for f in $(find .) ; do echo "$f" ; done . ./a ...
5
votes
3answers
1k views

cp doesn't work in script but works in terminal

Now, this is a strange problem, I have this kind of script: CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" RESOURCES_PATH="${CWD}/resources" PROJECT_NAME="something" ...
8
votes
3answers
208 views

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
3
votes
2answers
1k views

“grep: Unmatched [” error when using regex

I'm trying to find a pattern similar to this: tail -n 100000 gateway.log | grep -B10 -A10 'Nov 22 11:13:56 Received Packet from [10.50.98.68' Where "11:13:56" could be any time. This is what I ...
2
votes
1answer
176 views

Can't echo or create a symbolic link to a file with special characters in its name inside bash script

I'm trying to create a symbolic link to files with the following naming convention: .$abc$namehere.zip;1 As can be seen, it has the following special characters in it: . $ ; In my bash script I ...
2
votes
1answer
78 views

date doesn't accept its own output

What is the option for date to give output in a format acceptable to date --set ? I'm trying to remotely set the date, using the current computer clock of my workstation. ssh user@host sudo date ...
1
vote
2answers
218 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
4
votes
2answers
398 views

Word-splitting when parameter is used within command substitution

What needs to be done to ensure that a parameter containing embedded spaces is handled correctly when used within a command substitution? Perhaps an example will illustrate $ file="/home/1_cr/xy z" $ ...
3
votes
1answer
175 views

How can there be a directory named `~`?

I was trying to test out this buggy/new tool to see how it works, and it prompted me to choose a directory to use for stuff I am doing. From the directory ~/Code/indep, I typed in ...
4
votes
4answers
486 views

How can I grep for a string containing regex metacharacters like $ and '?

I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially: grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" . But it returns no ...
5
votes
1answer
273 views

Variable in sed

I have a file that contains filenames with absolute path. In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the ...
4
votes
3answers
935 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
6
votes
4answers
2k views

What is the difference between echo `date`, echo “`date`”, and echo '`date`'?

What is the difference between these three commands? echo `date` echo "`date`" echo '`date`' I am confused on what the differences actually are. I think that when the ' are around it means that it ...
9
votes
2answers
666 views

Are quotes needed for local variable assignment?

Can I safely omit quotes on the right side of a local assignment? function foo { local myvar=${bar} stuff() } I'm mainly interested in bash, but any info on corner cases in other shells are ...
0
votes
2answers
302 views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
1
vote
1answer
145 views

What is the difference between ' and "? [duplicate]

I tried to create a text file in a bash script. The echo command spans multiple lines and has some double quotes "". #!/bin/bash echo "blabla bla bla bla "blabla" bla bla " bla bla bla" and so on ...
2
votes
2answers
112 views

Awk not rendering any result

My goal is to get the file created in the current month in a directory. It seems that the command is correct but not rendering any result: Date=`date '+%b'` echo $Date Oct ls -l | awk -v d="$Date" ...
2
votes
2answers
141 views

Zsh possibly adding quotes to variable value (works in bash though)

I'm fairly new to zsh (shifted yesterday from bash) I had a bash function in bash like vl() { cmd=`echo $1 | sed -r 's/(.+):([0-9]+).+/\1 +\2/g'`; vim $cmd } This basically converts a argument ...
2
votes
1answer
109 views

Why does copying from a script screw with my files?

I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the ...
12
votes
0answers
356 views

Should I use $* or $@? [duplicate]

Which one of $* or $@ is better to use (in array syntax,command line parameters, etc.) to avoid any bugs/problems in code? Or it does not make any difference?
2
votes
1answer
98 views

Why does backslash get converted to space in echo statement if IFS='\'?

Why is \ is converted to space on setting IFS='\' var="'(]\\{}\$\"" IFS='\' echo $var # '(] {}$"
0
votes
1answer
3k views

Why does scp say “No such file”?

I have a bash script that uses scp to copy a file from my machine to another. The script keeps on exiting after I enter the SSH password with the error: <filename>: No such file or directory ...
1
vote
2answers
650 views

awk,how to change the value of the file using parameter sets?

I am trying to reset my data using awk. I have a data of 54 columns where I want to change six of the column values using the following script. #!/bin/bash -x # optimal parameters set ...
5
votes
2answers
3k views

Single command taking two strings to extract string between them, like 'tr' (without expressions)

Saw here a way to use sed to get text between two other strings in a line, like: sed 's/.*starting_text\(.*\)ending_text.*/\1/' but I'd like a simple command (like tr, but for string extraction) ...
2
votes
1answer
2k views

bash: export: `--wait': not a valid identifier

When I run git-sh from my terminal it works fine. But I get the following warning. bash: export: `--wait': not a valid identifier What is this and how do I get rid of it?
1
vote
1answer
2k views

Decrypt file using gpg in batch mode when passphrase includes a “!”?

I am trying to decrypt a file in a script with gpg batch mode, but command is not executed because the passphrase contains a "!" echo "m!pass"|gpg --batch --passphrase-fd 0 --decrypt-file plain.gpg ...
4
votes
2answers
314 views

Why do I need to escape regex characters in sed to be interpreted as regex characters?

It seems e.g. cat sed_data.txt | sed 's/\b[0-9]\{3\}\b/NUMBER/g' that I must escape characters to form a regular expression. In this case I had to escape braces in order to be interpreted as a number ...
2
votes
1answer
109 views

How to grep including single quote in a file

I have this line from file.php: 'user' => '', What would be the appropriate command using grep to query the exact line?
0
votes
2answers
355 views

sed with auto escape character [duplicate]

CommentAppend() { # Comment line and append line below commented line local comment="$1" # search this line and comment it local append="$2" # Append this line below commented ...
4
votes
2answers
1k views

How to run a remote sed command through ssh if the data includes double quotes (“”)?

I'm trying to run through a list of servers and run the next command: itaig@itaig-lt:~$ ssh root@$srvname "sed -i 's/VNCSERVERARGS[6]="-geometry 1920x1080"/VNCSERVERARGS[6]="-geometry 1152x864"/g' ...
2
votes
3answers
3k views

Using a reference to a bash string variable in sed

I'm a relative Linux novice. Suppose that I have a text file a.txt that contains the following text: A B C Now, if I want to change the text on line 2 (which contains B), I can use the following ...
4
votes
4answers
3k views

How to grep for pipe |

How can I grep for line containing pipe character | or for character >: files content: |this is test where is > this is none now what I need using grep command is grep -iE "<some ...
1
vote
3answers
898 views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I ...
3
votes
3answers
693 views

Quote a variable in shell script “if” statement

e.g. if [ "$FOO" = "true" ]; then vs if [ $FOO = "true" ]; then What is the different? Seems both of two statements also works.
2
votes
4answers
693 views

Why is bash interpreting characters that I have character escaped? [duplicate]

Why is it that when I run curl against a REST API, the special characters (!) in my key are interpreted by the shell? curl https://foo.my.salesforce.com/services/data/v28.0/ -H "Authorization: ...
6
votes
1answer
173 views

Where does this convention for quotation marks (`` …'') come from? [closed]

Frequently I get asked the question: ``K., where does this convention for quotation marks come from? You know, the one with the two grave accents introducing a quoted string and two regular ...
3
votes
1answer
123 views

How to make the command multi-line?

The following command: thunderbird -compose to=abc@example.com,subject=testmail,body="something" works, but only if it has no comma in the body tag. It works with: "dsafdsafcc \/sda/fads ;.f af af ...
2
votes
1answer
2k views

Screen escape dollar sign

I'm trying to run a command using screen which contains the dollar sign, but the dollar sign does not get through. screen -d -m echo \$ > test.txt test.txt just ends up being an empty file...
2
votes
2answers
5k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
14
votes
1answer
2k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
3
votes
2answers
1k views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
10
votes
2answers
357 views

What is the difference between “*.pl” and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
2
votes
2answers
555 views

Bad substitution inside xargs subshell?

I'm using this command to process PNG files: find . -iname "*png" -print0 | xargs -r0 --max-procs=4 -n1 sh -c 'pngnq -s1 $1 && advpng -z -4 -q ${$1%.*}-nq8.png' - It seems to actually work ...
2
votes
1answer
2k views

Executable symbolic link file not working

On Mac OSX, I am having trouble with a pretty simple thing. My symbolic link doesn't want to execute. Can you help me spot the trouble? Thanks! $ echo $PATH ...
0
votes
3answers
100 views

I need to turn a series of commands piped together into an alias in .bashrc

sudo ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' The above command when run from terminal outputs the right "internal" ip address. When I try to pass as alias like: alias ...
5
votes
2answers
589 views

Quoted vs unquoted string expansion

for i in $(xrandr); do echo "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done I understand why 1 differs from 2. But why does 3 give a different output ...
2
votes
1answer
170 views

Prompt user for sentence and store it without being disturbed by spaces

I have a bash function that prompts user to input certain data. I tried it with first name, last name, birthday etc. Data that is mostly represented in one sentence. When I ask for street + no. the ...