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

learn more… | top users | synonyms

4
votes
4answers
457 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
267 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
800 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
609 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
284 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
144 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
140 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
97 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
643 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
297 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
107 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
343 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 ...
3
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
2k 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
764 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
630 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
643 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
172 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
118 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
1k 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
4k 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
354 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
528 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 ...
1
vote
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
98 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
527 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 ...
1
vote
1answer
157 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 ...
3
votes
6answers
11k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
2
votes
2answers
890 views

Pass arguments to function exactly as-is

I have the following function: bar() { echo $1:$2; } I am calling this function from another function, foo. foo itself is called as follows: foo "This is" a test I want to get the following ...
1
vote
1answer
443 views

7z getting an event not found error in command line

I am using 7zip on my centos machine and ziping a file via command line. This is my syntax 7za a -t7z backup.7z public_html\ -mx0 -xr!restricted_area What i'm expecting with this syntax is to ...
2
votes
4answers
3k views

sh and grep numbers only

I'm facing a problem and trying to find a solution that works in sh. If I could use bash this code would work: ls /a|grep ^[0-9] Unfortunately this is not the case with sh, and yes I need to use ...
0
votes
1answer
191 views

Unexpected whitespace using sqsh in command substitution [closed]

Below shell script instruction behave in weird way ARG_DATE=`sqsh -S $SERVER -U $DB_USER -P $DB_PASSWORD -D dbname -h<<END SET NOCOUNT ON go select convert(varchar, PRIOR_COB_DATE, 112) from ...
1
vote
2answers
130 views

Bash variable into html

I have a script that gets the filenames in a folder and creates HTML link to them on my homepage. Here is the script: #!/bin/bash list_dir=`ls -t /path/to/dir/` for i in $list_dir do echo ...
3
votes
1answer
84 views

find utility does not recognize bracket notation

I've two files in the current folder: submitWeb.m submit.m the following find does not show the two files: find . -regex .*submit\(Web\)?\.m But the above regex expression works fine in ...
2
votes
3answers
3k views

sed - how to replace a single quote?

This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click ...
6
votes
2answers
347 views

Bash : command line with optional arguments

I'm running this kind of code: #!/usr/bin/env bash set -u exclude1='--exclude=/path/*' exclude2='--exclude=/path with spaces/*' exclude3='' # any 'exclude' can be empty tar -czf backup.tgz ...
2
votes
3answers
648 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
2
votes
3answers
286 views

Can I reload variable in a watch command?

Part of my job involves some data handling. One of the tasks is to 'flatten' a set of directories (which we'll call Dir for now), and copy them to a new location called DirFlat. This can take a long ...
2
votes
1answer
109 views

replacement inside parallel command string

I want to download multiple files and save them to the md5 sum of its name: cat list | parallel -j4 "md5=$(wget -O - {} | tee tmpfile_{#} | md5sum | cut -d ' ' -f 1); mv tmpfile_{#} $md5" but the ...