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

learn more… | top users | synonyms

0
votes
2answers
40 views

Echo a string with a variable in it without expanding/evaluating it [closed]

I've searched everywhere. Tried echo and print. Tried single and double quotes. But I have parsed data and assigned it to a variable and would like to then evaluate it for if there is a variable ...
3
votes
2answers
58 views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, i.e. read -d '' <variable> script block ...
0
votes
0answers
31 views

Is it possible to ssh and execute a remote command with a single quote in it? [duplicate]

ssh user@host "mv \"/some/path/fi\'le.txt\" /some/new/path" It doesn't matter what I do, or what combination of quotes I use on the file, it gives the following: bash: -c: line 0: unexpected EOF ...
5
votes
2answers
39 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
1
vote
1answer
21 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
4
votes
2answers
99 views

How to insert newlines into PATTERN when using fgrep / grep -F / grep --fixed-strings

When using fgrep, the man page says it will Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. In bash, what's the correct way to insert ...
0
votes
2answers
29 views

Bash script doesn't convert variables [duplicate]

I was attempting to create a bash script to run a backup of my Raspberry Pi to my Box account via FTP. Most of it works, but for some reason it won't convert variables to the text they stand for. When ...
0
votes
1answer
32 views

Parenthesis on echo shell command

I have this echo command: $ echo "alias notepad++="C:/Program\ Files\ "(x86)"/Notepad++/Notepad++.exe"" >> ~/.bashrc As shown in the picture it does not recognize the parenthesis.
1
vote
2answers
53 views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
0
votes
0answers
16 views

Bash variable containing JSON splits on single quotes [duplicate]

(Apologies for the poor title, I'm not sure what the exact cause of my problem is which makes it hard to describe, I just know I can't get it to work.) I have a variable which contains JSON. I'm ...
1
vote
2answers
62 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 ...
15
votes
6answers
561 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
81 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
32 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
48 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
30 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
75 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
36 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
646 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
40 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
33 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
81 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
26 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
39 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
55 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 | ...
1
vote
1answer
30 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
200 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
166 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 ...
1
vote
1answer
64 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
78 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
56 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
54 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
80 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
52 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
72 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
79 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 ...
1
vote
1answer
41 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
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 ...
1
vote
2answers
80 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
67 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 ...
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 ...
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
25 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
132 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 ...