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

learn more… | top users | synonyms

2
votes
2answers
65 views

Comparing strings with special characters using if-loop does not work

I want to compare each line of a particular file with the following string #orb_plugins = ["local_log_stream", "iiop_profile", "giop", "iiop"]; ("file.txt" contains this particular line) I tried ...
2
votes
6answers
5k views

How do I pass a variable from my local server to a remote server?

I am trying to pass a variable from my local server (location1) to a remote server (location2). The purpose of the code is to copy a file from the remote server from a predefined location. In simpler ...
1
vote
2answers
85 views

How does 'find -exec' pass file names with spaces?

If I have a directory containing some files whose names have spaces, e.g. $ ls -1 dir1 file 1 file 2 file 3 I can successfully copy all of them to another directory like this: $ find dir1 ...
2
votes
1answer
69 views

bash regex: asterisk gives ambiguous search results with grep

I am using a simple text file to test the * meta-character through grep. The text file is as below: 1 11 111 1111 11111 111111 d da daa daaa b bc bcc bccc Now when I search digit 1 using grep ...
2
votes
2answers
41 views

How to escape metacharacters for egrep like metaquote from Perl?

Perl has a function called metaquote() to escape all special characters for a regular expression. Is there an equivalent technique for egrep? Example: If I am searching for the string abc.def.ghi, I ...
3
votes
1answer
116 views

Assignment to variables

I was trying to devise a solution to a different question asked on the site and came across this curious issue. Here is the set of commands that I issued: $ foo=82a9948422 $ echo $foo 82a9948422 $ ...
13
votes
2answers
955 views

How can variables use “~” for cd'ing?

How can I use a variable - $BASE in my cd. I tried the following but I get an error $ cd ~/z/repo_1_ruby_193/ 23:23:57 durrantm Castle2012 /home/durrantm/z/repo_1_ruby_193 $ BASE="~/z" 23:24:03 ...
4
votes
3answers
2k views

New line in bash variables

I'm trying to store multiple lines in a bash variable, but it doesn't seem to work. For example, if I list /bin one file per line and store it in $LS, then I pass $LS as stdin to wc, it always ...
1
vote
2answers
70 views

Makefile shell ignoring sed regexp end of line

I have a folder for various testing of C code, containing many files named *.c. My aim is to have a Makefile search for any filename ending in .c and add the root of that filename to the targets. ...
1
vote
2answers
47 views

Internal expansion with the find command and wildcard character [duplicate]

I'm still learning the command line and I am having some trouble fully understanding the use of the wildcard within the find command. I'm working in the directory user/temp and use the find command ...
0
votes
0answers
32 views

Quoting the pattern in grep and it's still interpreted as an expression?

I have a simple script that I'm using to find CSS definitions in a vanilla bootstrap.css file, then I'm trying to find overridden/duplicate definitions in several other css files where other ...
2
votes
3answers
20k views

How to tell grep to match special character at beginning of each word [duplicate]

I have certain questions regarding grep. Why does the following command match '<Hello'? $ grep -E "\<H" test Hello World <Hello H<ello What needs to be done to match '<Hello' only? ...
2
votes
4answers
143 views

echo \\* - bash backslash escape behavior, is it evaluated backwards?

So in bash, When I do echo \* * This seems right, as * is escaped and taken literally. But I can't understand that, when I do echo \\* \* I thought the first backslash escaped the second one ...
77
votes
3answers
42k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
1answer
40 views

Having trouble with img2pdf and spaces in filenames

I am trying to convert a bunch of jpeg files to a pdf file. When I type the filenames with the quotes all is fine: $ img2pdf "./Page 001.jpg" "./Page 002.jpg" -o book.pdf When I go for the ...
2
votes
2answers
114 views

shell script with interesting bug

I've found such behavior of bash GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) and even latest ( How to get version of dash? ) dash on Debian. Bug as is: /bin/echo "Silent Err ...
0
votes
1answer
44 views

ssh pass multiple values

I want to open some ports i do for i in centos7{3..4};do ssh -T $i "for ir in 53 80 443 3000 3306 5910-5930 5432 8140 8443 10090-10100 20 21;do firewall-cmd --permanent --zone=public ...
0
votes
0answers
26 views

How to quote for Maildrop's xfilter?

I am trying to setup up a filter that resolves these "Re: AW: Re: Rif: Subject..." catastrophies. if( /^Subject: (Re: |AW: |Antwort: ){2,}/ || /^Subject: AW:/ || /^Subject: Antwort:/ ) { ...
35
votes
3answers
17k views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
0
votes
1answer
61 views

ln -s removes part of a file name, when filename is passed as a variable

I use a script to link some of the files I download to a different directory. When there are "-" in the file name, ln - s wont read the path correctly, even though the variable will be logged ...
3
votes
3answers
86 views

Why are square brackets preventing shell expansion?

'4800483343' is a directory, and 'file1' & 'file2' are two files in it. Why is the following happening? $ ls 4800483343 file1 file2 $ md5sum 4800483343/* 36468e77d55ee160477dc9772a99be4b ...
0
votes
2answers
101 views

Variable expansion inside parentheses and quotes

In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parentheses which I guess is ...
2
votes
2answers
53 views

Bash [[ pattern matching not working

The Bash reference section on conditional constructs says: When the ‘==’ and ‘!=’ operators are used, the string to the right of the operator is considered a pattern and matched according to the ...
2
votes
3answers
85 views

How to substite a " in awk?

For example, I need to change a " into the word quote in to change a string with a " at some point into a string with a quote at some point I have tried: $ echo 'a string with a " at some ...
44
votes
5answers
61k views

What does ` (backquote/backtick) mean in bash?

I came across the following command sudo chown `id -u` /somedir And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does ...
2
votes
1answer
38 views

How to assign file names with space to another variable without losing the separator [duplicate]

I have a bash script like: files="${@:2}" for f in $files; do echo $f done which takes the shell expansion from the second argument to the last, and print it. However it does not work with files ...
2
votes
1answer
382 views

grep and command-line variable substitution

In the following command sequence, $ grep -E '^.{11,22}John' emplist Operations John Thompson PARTHawks Cher Sales John Jacobs FULLHawks Davinder Singh Finance ...
1
vote
2answers
47 views

Bash variable changes when inside quotes

I'm trying to grab the first file matching a pattern and use that in a statement. Using the same steps as found in How can I get the first match from wildcard expansion? I wrote the following: ...
0
votes
2answers
109 views

ssh me@remote “<script with a for loop and variables>” - problem with variable expansion in for loop in remote script

Note - I posted a similar question yesterday and got a bit further thanks to @cas but am still having problems. I've refined the question so have re-asked it. I'm passing script text to an ssh ...
3
votes
2answers
218 views

Passing script string to ssh from within a bash script function - variable evaluation problem

I'm trying to write a bash script that runs a remote script via ssh as below: #!/bin/bash logfilepattern="*drupal*.gz php*.gz error*.gz" function getlogcounts { echo "in getlogcounts" echo ...
5
votes
3answers
3k 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. ...
1
vote
2answers
27 views

How do I prevent $@ from clashing with double quote in bash?

The following example returns "a b" instead of expected "a b c": test() { bash -c "testargs() { echo \$@; }; testargs $@"; } test "a b" c It seems it's a quoting issue. How do I solve it without ...
1
vote
1answer
48 views

bash error on eval containing blank space

I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this: ./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' On ...
0
votes
0answers
36 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
3
votes
2answers
1k views

Execute command through SSH

I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra ...
2
votes
1answer
1k views

Run a command under sudo over SSH

I am accessing remote machine in Linux using Bash scripting.My code is as follows #!/bin/bash ssh -i manu_bp.pem ubuntu@54.68.67.68 <<EOF sudo -s cat ...
0
votes
0answers
24 views

How to reference a variable by its string “name”? [duplicate]

Say for example... #!/bin/bash a1=one a2=two a3=three for x in {1..3}; { echo -n "\$a$x "; } Actual.. $a1 $a2 $a3 Expected.. one two three How can one echo, reference, call, or what ...
1
vote
1answer
57 views

Why is bash expanding history/exclamation-mark when between single quotes

I am creating a script to configure a server from scratch, part of this is postgres. One of the issues I'm having is if a random password has an exclamation it seems to be expanded by bash: I want ...
1
vote
4answers
256 views

Bash: move files of specific pattern

I write a script that iterates over a set of zip files, extracts them and moves only files that match a specific filename pattern to another folder. The script: #!/bin/bash ...
14
votes
6answers
2k views

Why there is such a difference in execution time of echo and cat?

Answering this question caused me to ask another question: I thought the following scripts do the same thing and the second one should be much faster, because the first one uses cat that needs to open ...
0
votes
3answers
55 views

How to correctly use quotes in sed? [duplicate]

For example I want to change "'this text'" "that text" 'other_text' into 'this text' "that text" 'other_text' I tried sed -e 's/^"\'/"/g' but my quoting must be off. Ubuntu.
1
vote
2answers
56 views

Cannot run command inside bash variable including square brackets with nullglob

Assuming I want to run commnand stored inside the variable with nullglob turned on. For example: shopt -s nullglob a="echo [foo]bar" ${a} This gives me an empty output due to the nullglob option of ...
1
vote
2answers
77 views

Issue when I try passing parameters to find command?

Parameter: export exc_lst='! -path "/var/app/s2/pnl/incoming/recondata/*.*"'; When I try using the below find commands: find $FILE_DIR -name "*.*" "${exc_lst}" -type f -mtime +20 -user sh79790 ...
2
votes
2answers
3k 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 ...
17
votes
2answers
5k 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 ...
2
votes
1answer
106 views

In bash, grep for a line beginning with \, and assign the result using backticks

In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks. For example: echo \\Hello > myFile out=`cat myFile | grep '^\\Hello'` echo $out returns ...
1
vote
1answer
138 views

Bash - syntax in echo

When using /bin/bash, what is the difference between the following two cases: echo $IFS echo "$IFS" I observe different outputs.
2
votes
1answer
54 views

python Vs bash string slicing

My file a contains the text, bcd\\\\. With bash, i read the file and print characters from 4th to 8th position as, tmp=$(cat a) echo "${tmp:3:4}" It prints, \\\\ All happy. Now i use ...
2
votes
2answers
2k views

Running system bash command in PHP script - syntax error: unexpected T_LNUMBER

Below is an extract from a script that I've written in PHP, but contains a system command that executes in bash. Now, the reason for this is because it allows me to use the awk function which is ideal ...
4
votes
1answer
358 views

Match pattern \\\" using grep

I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the ...