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

learn more… | top users | synonyms

2
votes
3answers
35 views

Command substitutions vs backslash escapes in a quoted string

Consider a double-quoted command substitution with backslash escapes inside it, like this: echo "$(echo '\\')" It prints out \\, whereas I would have expected it to print out only one backslash. My ...
-1
votes
1answer
30 views

Mutiple commands after sudo in one line

I want to execute multiple commands after a sudo command su - appuser -c "cd /apps/bundle/bundle-client/bin ; export BDL_WEB_USER=not_used ; export BDL_WEB_PASSWORD=not_used ; ./bundle -b ...
0
votes
1answer
47 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
2
votes
4answers
109 views

How do I perform xargs grep on grep output that has spaces?

I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like #Find all C++ files that match a certain pattern ...
1
vote
1answer
45 views

awk pattern with variable in a bash script

I have problem with command awk in bash I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line? awk -F" " "/$PWD/ {print $1,$3}" file.txt
1
vote
1answer
38 views

BASH: looping through ls [duplicate]

I'm having trouble with this piece of code: 22 for filename in "$( ls "$1" | grep ".*\.flac$" )"; do 23 file_path="$1${filename}" 24 ffmpeg -i "${file_path}" -f ...
0
votes
2answers
27 views

Why is wget still failing even after enclosing the URL with double quotes?

I enclose URLs I want to wget with "" since most of them have spaces, braces, etc. It usually works fine, but I can't get this URL to work: wget "http://xxxx/Sankarea - 6 - It`s Because I... Ran ...
1
vote
2answers
47 views

sh -c: Unterminated quoted string error [duplicate]

I've spent hours trying to understand the following error. My Script CMD="sh -c 'echo \"a\"'" $CMD Error: "a"': 1: "a"': Syntax error: Unterminated quoted string of course when I do echo $CMD ...
1
vote
2answers
274 views

How to put $@ in quotes?

My bash script looks like this: #!/bin/bash grep -r --color=always $@ . | nolong The file is saved in /usr/bin/findstr Everything's ok when I run this: findstr hello But when I run this: ...
4
votes
2answers
78 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...
1
vote
1answer
33 views

Replace a string in a text file using a shell script not working properly

I have a text file containing this: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1 and I want to replace the 1.0 to 2.0 so that it becomes: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1 so I use this ...
0
votes
2answers
59 views

ssh inside a script with 'command' instead of “command”

I am trying to run commands on various nodes of our cluster automatically via a simples script. I have seen that I can run: #!/bin/bash echo "Machine: "$HOSTNAME; ssh machine2 'echo Machine: ...
1
vote
4answers
43 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 ...
1
vote
1answer
39 views

How to pass a path to a file through a call to perl from bash?

This is a more advanced version of a previous question (How to pass arguments to perl when trying to change a line?) I made. This time I am trying to pass a path, but evertything seems that the the ...
1
vote
1answer
31 views

Create tar files from shell script with current time stamp

I am trying to create a shell script which will back up my git codebase and save in a specific back up directory with current days name So far I have : #!/bin/bash branch="master" if [ $# -eq 1 ] ...
1
vote
2answers
43 views

Single or Double quotes when defining an alias?

I know that contents of double quotes are expanded, whereas the contents of single quotes are not, such that echo '$1' gives $1 where as echo "$1" gives <the argument - blank in this ...
0
votes
1answer
204 views

Replacing white-space / characters with backslashes [duplicate]

I want to convert a bunch of mkvs to mp4s with the following command: for i in $(ls *mkv); do ffmpeg -i $i -vcodec copy -acodec copy $i.mp4; done; However, the filenames have whitespaces and ...
1
vote
2answers
34 views

Any special permission ssh remote command working on fifo file(aka named pipe)?

I need to redirect some strings to a fifo file with ssh remote command, but always got permission denied, the command I executed is: ssh rundeck@nagios1 sudo su - root -c 'printf ...
2
votes
2answers
32 views

Why is a variable passed to the su command, but not an array from the same scope?

In the example below, why does $var get passed to the su in the start function, but not the array modules ? #!/bin/bash var=cat modules=( one two three four ) start() { su gleventh -c "for i in ...
0
votes
2answers
22 views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
1
vote
1answer
26 views

ksh “<<EOF” script to change user

In the simplest form I am puzzled why this script does not work as expected as a here script changing users with su - user <<EOF. su - db2prd<<EOF PARMDATE=1111111 echo parmdate echo ...
1
vote
1answer
55 views

how to locate a name-not-specified file in bash? [closed]

I have a bash like this to easily upload a file to my server: FILE=../"$1"/1.txt scp 1.txt remoteserver #upload the file to a remote server. The $1 is for input directory and I have a lot of ...
4
votes
2answers
271 views

How to echo `single quote` when using single quote to wrap special characters in shell?

I'm reading shell tutorial today from http://www.tutorialspoint.com/unix/unix-quoting-mechanisms.htm In which it mentions: If a single quote appears within a string to be output, you should not ...
1
vote
3answers
52 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
77 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
47 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
47 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
47 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
76 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
160 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
281 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
43 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
24 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
68 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
38 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
200 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
65 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
40 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
84 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
107 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
49 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
24 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
36 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
39 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
185 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
58 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
152 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
32 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
120 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 ...