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
51 views

how to express line feed in shell?

Im my debian7.8 bash shell. str="deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free \n deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free " echo $str > ...
2
votes
1answer
65 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...
0
votes
1answer
35 views

pass quoted string argument in sh script

I simply don't understand command-line (works): $ someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh direct (works): #!/bin/sh someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh variable ...
0
votes
1answer
41 views

Make does not work when invoked from a bash script

So i just asked a question : for loop over a list This works perfectly now and outputs what i need. Now i want to link this to a makefile which should be called per variable in my list like this: ...
0
votes
2answers
44 views

How to use variables properly in this little script?

Here is a little script to retarget old-wrong symlinks that I want to make interactive. #!/bin/bash # retarget (broken) symbolink links interactively echo -n "Enter the source directory where ...
2
votes
4answers
69 views

Tool for escaping all quotes in a string/file

I have a weird problem that I don't have a good way around. My company, because reasons, stores scripting code in a database table. Don't ask. Whenever I have to insert a new version of the code, I ...
1
vote
3answers
108 views

sed won't expand my BASH variable in script

I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed ...
3
votes
3answers
271 views

Why awk understand FS=“*” but not for FS=“-*-”?

I got a test file, its content is: a -*- b I used awk 'BEGIN {FS="*"} {print $2}' test, it prints out - b Correct! But when I use awk 'BEGIN {FS="-*-"} {print $2}' test, I got: * I know that ...
1
vote
2answers
35 views

Why quotes are retained in string variables when surrounded by single quotes?

I needed to retain the double quotes around a string variable defined in bash in order to be able to pass it to a dialect of the Scheme programming language. My question is why are the double quotes ...
0
votes
1answer
23 views

Can I treat all what I typed after a command as raw string?

I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f ...
0
votes
1answer
63 views

Bash escaping is confusing me

Lets say that I have a file (executable) called literally 'a\b'. It just echoes some stuff. Now I want to call that and I can do it by inputting user@machine:~/test$ ./a\\b into my console. Now ...
1
vote
2answers
36 views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n ...
1
vote
2answers
190 views

Why does “grep '.*[s]' file” work and “grep .*[s] file” doesn't?

Comparing grep '.*[s]' file with grep .*[s] file Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
0
votes
2answers
47 views

tcpdump filter expression breaks via adb

I installed tcpdump on my Android tablet and am running commands from a root adb shell. I'm working from the tcpdump man page examples, specifically this one: To print all IPv4 HTTP packets to and ...
0
votes
1answer
37 views

UnixWare 7 fails to pass variable to Linux

I'm new to Bash and I have a problem that find difficult to solve, may be easy for some. I have a really old SCO UnixWare 7 system with no SSH only RSH available. SCO doesn't exist anymore , I ...
3
votes
4answers
83 views

fgrep beginning of line?

I'd like to use fgrep to handle searching literal words with periods and other meta-characters in grep, but I need to ensure the word is at the beginning of the line. For example, fgrep 'miss.' will ...
0
votes
1answer
73 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 ...
1
vote
2answers
37 views

Quoting / escaping / expansion issue in “command in a variable”

I want to run a command such as this in a bash script: freebcp <authentication and other parameters> -t "," -r "\r\n" When run directly on the command line, the command works as expected. But ...
4
votes
5answers
238 views

How do you interact with a file named “!!”? [duplicate]

Out of rage, I quit vim by using :wq!!!. This created a file named !!. Given that !! references the previous command, attempting to interact with it yields interesting results. I tried rm ./!! and ...
2
votes
2answers
23 views

variable substitution in CLI and for loops

I am pretty sure this has been asked already in some form, I just cannot come up with a good find to search it. I want to have a script that do things N times and to which I can pass as a variable ...
1
vote
3answers
29 views

UNC Argument in bash scipt

I want to create a bash script with a "pure" UNC (i.e. I do not want to escape the backslashes literally) as an argument, i.e. something like: ./foo \\my\share\is\here However, as is natural, the ...
2
votes
1answer
34 views

Export path with space in directory name [duplicate]

I have a path "/third/party/city of las vegas" when cd the path I use "/third/party/city of las vegas". In .profile file I have exported the path to a variable as follows export ...
2
votes
2answers
99 views

How to use variables inside single quotes

I have an application which takes as an input attributes in double quotes embedded in single quotes. Take for example this right command: command -p 'cluster="cl1"' In order to automate it, I ...
2
votes
0answers
56 views

Is there a difference between double quoting a variable or a whole line in echo

When you type, for example, echo Variable "$var" is not initialised. and echo "Variable $var is not initialised." the front end result is the exact same (as far as I know, at least). But I was ...
2
votes
3answers
131 views

Variable expansion in Bash

I tried the following commands variable='one|name' echo $variable The output is one|name whereas echo one|name gives an error No command 'name' found. This is reasonable because bash treats | as ...
0
votes
1answer
29 views

Prepending text read from a file on the top of another file [duplicate]

I want to add "void mainfunction()" on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using sed -i '1i void ...
1
vote
1answer
89 views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
2
votes
1answer
74 views

How to use variables in sed command

I'm trying to run sed -i "/$variable/c \$variable1' file.txt But it's not displaying any change in the file: file.txt. But the same command, with out the variables works fine: sed -i "/variable/c ...
4
votes
3answers
161 views

Using | pipe character from a $variable makes it treat as just another argument in bash; how to escape it?

I have a bash script like this export pipedargument="| sort -n" ls $pipedargument But it gives the error ls: |: No such file or directory ls: sort: No such file or directory It seems to be ...
4
votes
2answers
180 views

Running commands stored in shell variables

The following works in my shell (zsh): > FOO='ls' > $FOO file1 file2 but the following doesn't: > FOO='emacs -nw' > $FOO zsh: command not found: emacs -nw even though invoking emacs ...
0
votes
2answers
73 views

Bash Script Parsing Argument not working correctly

i have the following bash script (taken from FFmpeg) #!/bin/bash ################################################################################ # # Script name: MultiMedia Concat Script (mmcat) # ...
2
votes
2answers
84 views

Is there a reason to quote the exit status $? variable?

I was looking at Google's style guides for their bash scripts, and saw that they quote the exit status variable $? here. if [[ "$?" -ne 0 ]]; then error_message fi I thought return values are ...
1
vote
1answer
149 views

Remote ssh command not sending echo variable from a ksh script on AIX

I'm need to get the value of a variable from a remote host in a script using SSH and have to source an environment file first that does a shift at the end of its run. The command works locally and I ...
2
votes
2answers
74 views

How do I write a command for the Exec key in a .desktop file containing a reserved character correctly?

I'm trying to make a .desktop file for Minecraft. Nothing appears to happen upon executing the file. I've tried assigning the Exec key as follows: Exec= java -jar "~/.minecraft/Minecraft.jar" Exec= ...
1
vote
1answer
35 views

why does grep '\;.' expand to grep '\''\;.'\''' when executed over ssh?

$cat test.sh ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'" $bash -x test.sh + ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c ...
1
vote
0answers
19 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 ...
8
votes
2answers
166 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
3
votes
1answer
71 views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
0
votes
1answer
35 views

Remove a folder with the same name as an environment variable

I was messing around with a log4j properties file and accidently made a folder with the following text ${foo} however I also have an environment variable named foo that points to a folder so thus if I ...
3
votes
1answer
72 views

sed repeating the last line in the stream

I have code in a script similar to this... smbconffile="/etc/samba/smb.conf" sed -i 's/.*[\[CMI\]]/\[CMI\$\]/' $smbconffile && echo "Success" || "Failed" sed -i 's/.*[\[LOCAL\]]/\[LOCAL\$\]/' ...
0
votes
2answers
53 views

How do I handle special characters like a bracket in a bash script?

I am trying to get the output of some programs and assign them to variables. I am using backticks to do it, but I can switch to a different method if necessary. What I notice is that often I do not ...
4
votes
2answers
270 views

How to quote arguments with xargs

Suppose that I want to delete all files in a folder that are greater than 1 MB. $ find . -size +1M | xargs -0 rm This will not delete files that have space in their names. So I want it to quote all ...
2
votes
3answers
57 views

SSH command with file redirect not working

I want the following command's result to redirect into a file on the remote server, as I want only unique lines in my authorized_keys file: ssh root@10.100.10.26 awk '!seen[$0]++' ...
43
votes
1answer
1k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
2
votes
1answer
30 views

rsync exclude-from directory with space

I am trying to exclude "Mendeley Desktop" directory for rsync. The exclude-from= is as: Downloads *.o *.iso Dropbox Documents/Mendeley\ Desktop but rsync is still backing up the Mendeley Desktop. ...
2
votes
2answers
75 views

Event not found in sed call in csh script

I tried the code as given on delete text between curly brackets however I am facing this different error regarding event in sed. file contains: This is { {the multiline text} file } that wants { ...
6
votes
4answers
339 views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' Can anyone help me to construct an example where the first form fails but the second still works. And tell me the difference between them.Thanks!
2
votes
3answers
118 views

How to parse env variable in a quoted string?

I'm having a hard time getting the value of an environment variable ($GHREPO) in a quoted string. Here is the command I'm running. I'm trying to make a directory with the value of ...
3
votes
2answers
227 views

single quote within double quotes and the bash reference manual

In section 3.1.2.3 titled Double Quotes, the bash manual says: Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception ...
13
votes
2answers
860 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 ...