8
votes
4answers
373 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
2
votes
2answers
44 views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
2
votes
2answers
184 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
0
votes
1answer
54 views

How can I echo dollar signs?

For example, $PATH and $HOME When i type echo $PATH it returns my $PATH, but i want to echo the word $PATH and not what the actual variable stands for, echo "$PATH" doesn't work either. It might ...
5
votes
1answer
36 views

Representing/quoting NUL on the command line

Can \0 be used on the command line? Background For testing corner cases in GNU Parallel I was curious whether all characters were correctly quoted on the command line. Most of them are: perl -e ...
2
votes
3answers
62 views

How to nest quotes in bash commands

I want to test the result of this command: dmesg | grep "Firmware patch 1563" Therefore, I try to write something like this: if [ "`dmesg | grep "Firmware patch 1563`" == "" ] But it doesn't ...
4
votes
2answers
167 views

How to escape single quotes correctly creating an alias

I've been given this one-liner to know how much memory my processes consume. $ ps -u $USER -o pid,rss,command | \ awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}' Now I'd like to ...
2
votes
2answers
48 views

Is there an improved version of “pick” that will work with filenames with spaces?

Is there a version of the pick script that will work properly with spaces in the filenames? This is a tricky question—pick is trivial to enhance to work with spaces in filenames, but the output ...
2
votes
3answers
93 views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i ...
5
votes
3answers
140 views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
0
votes
0answers
50 views

What is the difference between double quotes (“”) and single quotes ('')? [duplicate]

I really do not know the usage of " and '. I want to know usage of " and '. What is the difference between echo "hi" and echo 'hi'.
8
votes
4answers
390 views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, ...
7
votes
2answers
380 views

Bash string concatenation used to build parameter list

Given this piece of bash: PARMS='-rvu' PARMS+=" --delete --exclude='.git'" echo $PARMS rsync ${PARMS} . ${TARGET} The echo shows the PARMS string as expected, no error is displayed, but rsync ...
0
votes
1answer
40 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
4
votes
2answers
66 views

Inconsistent redirection behavior ssh interactive vs commands

These work, ssh remote 'echo hi > hi.txt' echo hi | ssh remote 'cat > hi.txt' but this does not work ssh remote sh -c 'echo hi > hi.txt' I expected to produce a file on remote named ...
16
votes
5answers
1k views

Parenthesis in bash arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
4
votes
1answer
582 views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
3
votes
5answers
322 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 ...
1
vote
0answers
119 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
527 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
48 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
97 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;"| ...
4
votes
2answers
252 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 ...
5
votes
1answer
179 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
57 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 ...
0
votes
1answer
220 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
138 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
425 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 ...
2
votes
1answer
121 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 ...
3
votes
3answers
106 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
81 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
328 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
187 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 ...
21
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 ...
2
votes
1answer
64 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 ...
1
vote
3answers
90 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
208 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
3k 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
4answers
357 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
118 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
339 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
607 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
325 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 ...
0
votes
1answer
67 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
595 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 ...
0
votes
1answer
103 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 ...
5
votes
4answers
5k views

Pass shell variable as a /pattern/ to awk

Having the following in one of my shell functions: function _process () { awk -v l="$line" ' BEGIN {p=0} /'"$1"'/ {p=1} END{ if(p) print l >> "outfile.txt" } ' } , so when called as ...
5
votes
1answer
149 views

understanding the default value of IFS

In my GNU bash version 4.2.8, IFS has a default value of space, tab and line feed by default: usr@T42 ~ $ echo -n "$IFS" | hexdump -C 00000000 20 09 0a | ..| ...
18
votes
2answers
2k views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
2
votes
2answers
391 views

Why does bash add single quotes to unquoted failed pathname expansions in a command before executing it?

I was exploring the tracing of commands using set -x (set +x to unset) in bash: Print a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and ...