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

learn more… | top users | synonyms

1
vote
1answer
70 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
3
votes
5answers
513 views

How to use a shell variable inside sed's s command? [duplicate]

we know that we can get the value of a variable using $ sign: x=3 echo $x 3 Is there other ways that we can use to get the value without using $ sign. I'm asking this because $ sign is a special ...
2
votes
2answers
88 views

How to escape spaces etc in passed variable, for system call to cp in awk

As the title suggests, this problem has enough layers of complexity to make simple escaping characters difficult for me. I have a bash script which, for a large part, has an embedded awk script that ...
2
votes
2answers
359 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
2
votes
0answers
158 views

How to pass multiple commands via pssh and multiple xterms

I'm attempting to open multiple xterms and run a command as an SAP user via sudo using pssh. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in the servers ...
5
votes
1answer
613 views

What does su - `whoami` command do?

I am running a script in my project and I see this command su - `whoami` I am having a few basic questions: What does this command do ? What is the significance of `` quotes outside the whoami ...
3
votes
2answers
62 views

How to build space separated, escaped full paths of files recursively matching glob?

I have a program which requires paths to files as arguments, which cannot be quoted and must not depend on working dir. Can this be done without chaining multiple xargs, tr, find, readlinks? Example ...
2
votes
1answer
160 views

Backslash with pipe in system command from awk

I want to invoke shell command from awk so I am using system() but when I am passing expression in I am getting error at backslash. Here is my expression echo "select * from abc limit 1;"| ...
5
votes
1answer
663 views

Why do I have to escape a “dot” twice?

I know that we can escape a special character like *(){}$ with \ so as to be considered literals. For example \* or \$ But in case of . I have to do it twice, like \\. otherwise it is considered ...
0
votes
2answers
107 views

Why does passing a HEREDOC as a string to `ruby -e` not work?

For reasons I don't understand, it seems to be impossible to pass a heredoc as an expression to a Ruby interpreter: $ ruby -e <<END heredoc> puts 'hi' heredoc> END ruby: no code ...
4
votes
2answers
426 views

Add arguments to bash -c

Let say that I want to run a command through bash like this: /bin/bash -c "ls -l" According to bash man page, I could also run it like this: # don't process arguments after this one ...
1
vote
1answer
72 views

How could I retain special character without replacing it with underscore?

I'm working on a file transfer script where I encounter a problem, when the file name look like Dr' A. The transfer script will fail due to following error: sftp> put /path/Dr'\ A.tif Unterminated ...
5
votes
1answer
191 views

Test -n gives unexpected result

I understand test -n <expression> to return false if the expression evaluates to a string length of greater than 0. Why then does the following happen? Macbook:~ echo ${#undeclared_variable} 0 ...
1
vote
1answer
62 views

How to enclose a quoted variable in quotes

I want to call: ./mjpg_streamer -i "./input_uvc.so -r 320x240" -o "./output_http.so -w ./www" from a C program, running system(). The problem is that I have to enclose shell command in quotes, which ...
2
votes
1answer
74 views

Could “>” be included in a bash Variable?

Current approach: sudo awk 'BEGIN{printf "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<hello>\n\t<world>\n";} {print "\t\t",$0}END{printf "\t </world>\n</hello>\n"}' ...
2
votes
1answer
89 views

Change a specific line using sed

I need to change a line in a Java file called DbConnection.java using the sed command. The line is: connection = DriverManager.getConnection("jdbc:mysql://**localhost**/**bajaj**","**root**", ...
1
vote
2answers
334 views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
3
votes
2answers
385 views

Variable assigned inside ssh command doesn't return proper value

I'm executing the below command in the ssh part of my script. The command is meant to cut the file size from ls option and storing it to a variable. Then print the variable: echo "Enter srouce file"; ...
1
vote
2answers
75 views

Problems with basename in a loop

I am new at shell script programming and I'm trying to execute a software that reads a text and perform it's POS tagging. It requires an input and an output, as can be seen in the execute example: $ ...
0
votes
1answer
161 views

How to exit the script in ssh session?

My script contains a ssh command to login to remote server and execute a few commands, The command checks if a file exist and if not it should come out of the entire script. ssh $user@$hostname "if[ ...
0
votes
1answer
260 views

Bash Script : Passing a variable to a bash script that contains quotes, single quotes. etc [closed]

lets assume this is the string: 'a',"b" it contains both single and double quotes. how would you pass this to a bash script as a single string ? this is the bash script: #!/bin/bash echo $1 ...
2
votes
2answers
166 views

“cat” command: how to automatically escape everything that might be a violation?

If you copy the contents of httpd.conf and then paste it into a cat command.. such as this one.. #!/bin/bash cat > /test << EOF pasted here.. EOF you run into this error: -bash: ...
0
votes
2answers
580 views

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

If anyone can shed some light on my issue that'd be great. Please don't down-vote me; I'm new to the language and the OS itself and I'm trying my best to research before asking questions, so any ...
1
vote
0answers
59 views

Why does vim color this .bashrc line incorrectly? Fixable?

I have the following line in my .bashrc that allows me to use rlwrap with sqlplus. Why does vim seem to color this wrong? alias sqlplus='rlwrap -c -f /usr/bin/rlwrap -b ...
2
votes
1answer
163 views

Why is my tar in a script behaving different than using tar manually

I'm writing a backup script for my email and cloud service. For simplicity, I only posted the mail-backup part here. Basically, I have a Host-Machine with some Virtual Boxes running in it. These ...
0
votes
3answers
61 views

How do I match a string with symbols in a grep-kind of way? [duplicate]

I have a file with this contents (or similar): # cat /var/www/htpasswd foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/ and I'm trying to verify the presence of an entry in it, by matching it, like this: ...
3
votes
3answers
148 views

Print a string including single quotes and other special characters

How can I write this with an AIX script correctly? My requirement is to write this command in test.txt: clock=$(prtconf -s | awk '{print $4,$5}') I tried this command: print 'clock=$(prtconf -s | ...
0
votes
3answers
106 views

Why doesn't source work when I call bash -c

I want to run a command that sources a script to take on some env. variables before executing, without sourcing them in my current shell. test.env export test=1 None of these commands echo the ...
2
votes
4answers
529 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 ...
3
votes
2answers
207 views

How do I echo an expression with both single and double quotes?

I have tried many things, but I'm new to the shell. Is it possible to have both double and single quotes within an echo? I want to generate echo "scan 'LPV',{FILTER => "(PrefixFilter ...
1
vote
1answer
121 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 ...
22
votes
3answers
2k 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
63 views

Problem in using user defined variable in a script

The following is a simple script, named myscript, that I wrote in order to run a command. dcmpath='$HOME/Data' dcmfile='IM1' dcm2nii $dcmpath/$dcmfile Unfortunately, bash does not recognize the ...
2
votes
1answer
69 views

How do I eval two commands?

If I run this: echo "echo 'a'; echo 'b'" It produces a string which I can then run, and it works - echoes a\nb\n. However, this does not work: $(echo "echo 'a'; echo 'b'") Why not? It doesn't ...
2
votes
1answer
94 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
1
vote
3answers
107 views

Why doesn't my command work when aliased?

I use ps -ef | grep catalina | grep -v grep to print the tomcat process running on the system: kshitiz 7099 1 0 May11 ? 00:02:29 /usr/lib/jvm/jdk1.8.0/bin/java ...
0
votes
1answer
303 views

Escaping multiple backticks in a sed call

I need to perform search and replacement iteratively in several SQL statements: From: CREATE TABLE `Old_Name` ( To: ALTER TABLE `Old_Name` RENAME TO `New_Name` The above query contains ...
1
vote
3answers
4k views

How can I run a “grep | grep” command as a string in a bash function?

I'm trying to build a command that pipes the results of one grep command to another grep command in a bash function. Ultimately, I want the command executed to look like this: grep -I -r FooBar ...
4
votes
2answers
6k views

Bash command in string is executing when I create the string, not when I use it later

I'm relatively new to shell scripting, but have nearly completed a script which makes use of the lftp program. The part of the script I am having trouble with is when I create a long string of ...
4
votes
4answers
416 views

Multiline variable with spaces, adding each line to an array

I have a problem I can't seem to figure out.. I'm making a script I will run in OSX to help me stay connected to open wifi hotspots. I am reading all surrounding wifi networks into a muntiline ...
-1
votes
2answers
155 views

Update .profile in /etc in UNIX

How can i append the following text in .profile in folder /etc/security of UNIX OS? PS1='hostname -s':$LOGNAME'[$PWD]' i tried: print 'export PS1='hostname -s':$LOGNAME'[$PWD]' ' >> profile ...
3
votes
1answer
506 views

Error with a file name containing parentheses

when I tried to change file name from old.file(1).gz to new.file.gz, It says syntax error, I am using ubuntu 12.04. mv old.file(1).gz new.file.gz bash: syntax error near unexpected token `('
5
votes
3answers
706 views

What is the difference having double quotes or not in bash [duplicate]

I have some bash scripts, one which has the following content: #!/bin/bash source $(dirname ${BASH_SOURCE[0]})/script.sh while the other one has the following content: #!/bin/bash source ...
2
votes
2answers
440 views

About escape with SSH pipe

I want to execute the awk command with long parameters,like this: ssh host "netstat -rn|awk 'NR!=1 && NF>=6 && $1!="Destination" {printf "%-15s %-20s\n", $1, $2}'|sort -f " but ...
2
votes
3answers
314 views

Renaming file which got a quote mark ' in its name

I got a little bit of a problem. One client tasked me with the migration of sites from a really old server. Don't know how they got there, but there are files with ' in their names. Is there any way ...
0
votes
1answer
68 views

Scripting - Folders with spaces

I'm trying to write a script that's robust enough to work with spaces. Its currently in a for loop, but the problem I'm having is folders with spaces in its name. ASOURCE="Home Photos 2012 ...
0
votes
5answers
783 views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the ...
3
votes
3answers
142 views

Change the name of a file that contains spaces in the name

I don't know why but when I go to change this file name with mv command it comes up with the error stating not a directory. -bash-4.1# mv {{ THEME SANITIZED }}.hacks.css myomega.hacks.css
0
votes
1answer
127 views

Commands inside bash not being interpreted?

I'm trying to execute a command inside a bash script, $(pwd) is not being interpreted at all, and not even using eval. This do not work: cat apache-vhost.conf | sed 's/{path}/$(pwd)/g' Neither ...
1
vote
2answers
61 views

Why my tabs are not expanding in TIMEFORMAT?

I need to measure the running time of an application, so I'm messing with TIMEFORMAT in order to print short format with the maximum precision available. From the Bash Refence Manual: TIMEFORMAT ...