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

learn more… | top users | synonyms

1
vote
2answers
87 views

bash -c in subshell gives EOF parsing error

Why does the following script work as expected (prints hello) #!/bin/bash foo=$(bash -c 'echo hello') echo $foo while this script: #!/bin/bash cmd="bash -c 'echo hello'" foo=$($cmd) echo $foo ...
16
votes
6answers
576 views

Should variables be quoted when executed?

The general rule in shell scripting is that variables should always be quoted unless there is a compelling reason not to. For more details than you probably want to know, have a look at this great ...
3
votes
2answers
202 views

Passing paths with spaces as arguments

I am having difficulty in passing some string variables having spaces in them as arguments to a program. For debugging and showing the arguments being passed, I created a demo Python script -: ...
1
vote
1answer
48 views

Run for loop via ssh

Good day All, I'm attempting to run a for loop via SSH. The loop is used to get the last login of each user that has an account on the server, ssh 172.20.2.1 '''for i in `cat /etc/passwd | awk -F: ...
1
vote
1answer
54 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: ...
2
votes
2answers
60 views

Exported variables inside ssh session are empty

I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo ...
2
votes
2answers
200 views

Passing multiple of arguments with whitespaces through a script to ssh

I want to remove multiple files from remote server. I have all files under one array in a script and I call other script which will remove files. Let output of "${b[@]}" is: ...
2
votes
1answer
37 views

quotes generated by another Bash script not treated like quotes inside original script [duplicate]

Using bash… my pwd contains directories with spaces: $ pwd /a/b c/d This works: $ ls "$PWD" bar foo # yay! It also works if I put that code inside a script. Now if I split that command in two: ...
5
votes
3answers
659 views

File name beginning with - (dash) [duplicate]

I have file called -l in my directory now I tried to do for i in *; do stat -c "%s %n" "$i"; done it lists all files with sizes but in the middle of the output there is something like 395 ...
2
votes
5answers
42 views

Help on edit a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
0
votes
1answer
34 views

Script with variable in path

I'm not entirely sure where to ask or how to formulate this question with correct terminology. I have script here for managing a game (minecraft) server for the user (bukkit). I've cut out some ...
1
vote
2answers
226 views

Remove file with pound signs around it [duplicate]

I am using SSH to another terminal with very limited disk space. upon typing ls I see a file called #korpus.txt#. I suspect this file is an emacs buffer, but upon running emacs and trying to kill it ...
1
vote
1answer
28 views

Why isn't this perl regex capturing the backreference?

I have a directory of files $ ls -1 ep2.mp4 ep3.mp4 ep4.mp4 ep5.mp4 ep6.mp4 ep7.mp4 I want to use the perl rename utility to make all files look like e.g. ep02.mp4 Command I am using rename -n ...
1
vote
1answer
74 views

How to declare some aliases dynamically in zsh?

I would like to declare a few shortcut commands to switch between my various coding projects, so I have come up with the following script. projects=$(ls -d ~/Workspace/*/) ...
1
vote
1answer
80 views

Inserting variables in a command within a shell script

I'm attempting to write an automated script which will update the IP address for my Raspberry Pi within my /etc/hosts file. I'm able to execute this line just fine, IP=`sudo nmap -sP 10.61.4.0/24 | ...
0
votes
1answer
37 views

Escape shell arg from one script to another

Given ./mysh0: #!/bin/bash exec ./mysh1 $* And ./mysh1: #!/bin/bash echo $1 echo $2 echo $3 How do I call mysh0 such that the arguments to mysh1 and what's eventually printed are "A", "B 2" ...
2
votes
1answer
19 views

Parameter ignored when quoted

I have a directory with 3 files: file1, file2 and the following bash script: #!/bin/bash set -e Command="ls -1 -I file1" echo "Command: $Command" Files=`$Command` echo "Files:" echo $Files The ...
8
votes
1answer
223 views

Bash script parsing argument with quotes

Please consider this simple script named test: #!/bin/bash echo $1 and the following commands and calls: $ echo "A B" A B $ echo ""A B"" A B $ echo """A B""" A B $ echo """A B""" A B $ ./test "A ...
2
votes
2answers
174 views

Do programs invoked by shell inherit shell variables?

If I have this shell script str="A tremor in the Force. The last time I felt it was in the presence of my old master." cat <<< "$str" My understanding is that the command cat ...
0
votes
1answer
68 views

escaping brackets and other characters in shell script

I have run the following command on the command line and it works fine, but when I try running it from a shell script and run shell script from the terminal I get the following error: join -t $'\t' ...
1
vote
2answers
90 views

Escape characters from echo -e

I have the following in my .bashrc file I use for a log: function log(){ RED="\e[0;31m" RESET="\e[0m" echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt } But when I do ...
0
votes
3answers
61 views

significance behind escaping parentheses in expr match

Can anybody give me the difference between the following two commands in the context of escaping parentheses, or refer some document that would clear my doubt. string=abcABC123ABCabc $ echo `expr ...
0
votes
2answers
61 views

How to write “!” symbol between double quotes in bash? [duplicate]

I can't figure out how to write ! symbol in bash scripts when putting it in double quotes strings. For example: var="hello! my name is $name! bye!" Something crazy happens: $ age=20 $ name='boda' ...
2
votes
2answers
142 views

Insert text in specific lines of a file? with special characters

i know this has been answered several times, but i can't figure out how to use it for my project. i have several php files and want to add a new string between line 11 and 12. this is the string i ...
1
vote
1answer
56 views

What does a backslash represent when searching for decimals

I want to understand what the backslash represents in this command. grep "\.900983" table I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
0
votes
1answer
157 views

Passing a variable argument to egrep in a bash script

I have a script, myScript, which is trying to egrep the script argument in a file. Somehow variable expansion isn't working properly with the egrep command. I believe I've isolated the problem ...
2
votes
2answers
172 views

How to escape single or double quotes when passing a variable to bash script?

Let;s say I have a script which echoes $1 #!/bin/bash echo $1 It's called test.sh. Then I call /bin/test.sh 'test'. The output is test. But this doesnt work: /bin/test.sh 'te'st' There's a ...
2
votes
1answer
84 views

Error when substituting part of curl command with variable

I'm writing a script where I am running curl commands several times. The use of the curl command varies throughout the script and I would like to save myself time (in the future when I have to debug ...
2
votes
2answers
153 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 ...
1
vote
2answers
176 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
76 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
57 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 ...
1
vote
2answers
95 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
61 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
43 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 ...
1
vote
1answer
44 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
119 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
64 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
35 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:/ ) { ...
3
votes
2answers
147 views

Shell-independent escaping for strings in scripts

I just struggled (again) over this: # only in bash NORM=$'\033[0m' NORM=$'\e[0m' # only in dash NORM='\033[0m' # only in bash and busybox NORM=$(echo -en '\033[0m') The goal is to include special ...
3
votes
3answers
109 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 ...
2
votes
2answers
69 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
1answer
40 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 ...
1
vote
2answers
48 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
159 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
345 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 ...
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
61 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
44 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 ...
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 ...