Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.
3
votes
1answer
131 views
Printing colored text using script
When I type below command in the shell I get the OUTPUT in green color.
Command
echo "\033[32mCONNECTING TO abpwrk\033[m";
Output(in green color)
CONNECTING TO abpwrk
But if I use the same ...
4
votes
5answers
540 views
How to enclose in quotes if both single and double quotes are already used?
I don't remember the exact commands and tricks that I use sometimes which solves much of the work, so I try to log them into a file for future reference. What I typically do is just put whole command ...
4
votes
2answers
135 views
Why am I observing different behaviour of echo?
I am a bash beginner and observed the below behavior of echo
#!/bin/bash
x=" hello"
echo $x
echo "$x"
Now when I run the above code I get
ronnie@ronnie:~$ bash test.sh
hello
hello
...
1
vote
4answers
119 views
Syntax error in a bash script that calls find
Where is the error in this script please:
#!/bin/bash
rep="git"
files=`find' ${rep} '-type f`
for f in ${files} do
echo $f
done
When i run find git -type f alone in the shell, it works!
3
votes
2answers
229 views
how to grep for c:\
I'm using cygwin's grep to find all instances of hardcoded paths on c drive.
doing:
grep -r "c:\\" .
gives grep: trailing backslash
Does anybody know how I can do this?
1
vote
2answers
193 views
Is there a way to get *actual* (uninterpreted) shell arguments in a function or script?
I have a function posix that I use in the Git bash shell on Windows to transform DOS-style paths to normal Unix-style paths. Since DOS-style paths use a backslash as separator, I have to quote the ...
0
votes
1answer
127 views
How to run svn when ssh over ssh?
I need to run sudo -u wwwrun sh -c 'svn status -uq /srv/www/htdocs/loquat' over ssh. When using one ssh it works smoothly. Now there is one server that needs to be connected through another server via ...
3
votes
1answer
130 views
Bash script with quotes and spaces
I'm trying to get some nice output out of git:
FORMAT='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
LOG_PARAMS="--color --pretty=format:$FORMAT --abbrev-commit ...
1
vote
1answer
67 views
Apostrophe appearing as space
I am trying to insert the following message:
friend's mobile number
from a file over redhat server into sql server 2005.
this message is appearing in the sql server as below:
friend s mobile ...
1
vote
2answers
122 views
run bash in script
I want to creat a script to run an another script with a several parameter
exp=([1]=bloc [2]=ins [3]=rep [4]=op)
for j in ${!exp[*]}
do
arr=([1]=mem [2]=gen [3]=usr)
for i in ${!arr[*]}
...
11
votes
3answers
928 views
What does it mean to have a $“dollarsign-prefixed string” in a script?
I just saw this in an init script:
echo $"Stopping Apache"
What is that dollar-sign for?
My research so far:
I found this in the bash manual:
extquote
If set, $'string' and ...
-1
votes
1answer
689 views
How to move file from one folder to another in shell script by changing the permission
I want to move a file from one folder to another folder.
When the file's format is with space in between (file _name.dat) and when I am using the command mv file _name.dat /tmp then the file is not ...
2
votes
2answers
182 views
Piping paths with different types of quotes for slash substitution
I would like to use sed to convert a path with backslashes to the same path with forward slashes:
E.g.
I would like to pipe \\path\to\file\ and obtain /path/to/file
None of the following commands ...
8
votes
2answers
1k views
How are parenthesis interpreted at the command line?
While reading up on how to set up grub, one article mentioned that I need to use a syntax like
echo \(hd0,0\) >> /boot/grub/grub.conf
or
echo '(hd0,0)' >> /boot/grub/grub.conf
...
2
votes
1answer
188 views
Command substitution: file or command not found
The following script
#!/bin/bash
QUERY='select * from cdr;'
MYROWS=$("sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db '${QUERY}'")
gives me
./bla.sh: row 35: sqlite3 -list ...
2
votes
1answer
114 views
Is it a bug for join with -t\t?
I have a problem with the command join. "The default join field is the first, delimited by whitespace" (Cited from join --help). However, there is a field containing sentences in my tab-delimted ...
1
vote
4answers
768 views
Appending a string containing escape character with sed
Currently I use:
sed -i -e "5a\\
${text}" $filename
to append something to a certain line, where the variable text
contains a string such as "\epsilon".
When using
echo -E $text
the string is ...
26
votes
7answers
2k views
How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)?
How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory:
tohru:~ $ ls -l
total 8
-rw-r--r-- 1 me ...
16
votes
3answers
4k views
Quoting in ssh $host $FOO and ssh $host “sudo su user -c $FOO” type constructs
I often end up issuing complex commands over ssh; these commands involve piping to awk or perl one-lines, and as a result contain single quotes and $'s. I have neither been able to figure out a hard ...
4
votes
1answer
354 views
How to run this in sudo?
I have this line that I execute from php
sudo -u db2inst1 -s -- "/opt/ibm/db2/current/bin/db2 connect to PLC; /opt/ibm/db2/current/bin/db2 \"update EDU.contact set MOBILE_PHONE = '123'\""
it works ...
2
votes
2answers
985 views
Change directory with space followed by '('
There are two directories I can change to:
Program Files/ Program Files (x86)/
I can change to first one by writing:
cd Program\ Files
But the second for second one:
cd Program\ Files\ ...
1
vote
2answers
287 views
Weird zsh grep -P behaviour
I connect to server with PuTTY from Windows.
I have a long yet not touched (I suppose) by hands of local admin config:
$ cat /opt/jira/.subversion/config
...
### must be enabled, which is ...
3
votes
3answers
1k views
Why does bash variable expansion retain quotes?
> echo "hi"
hi
> VAR='echo "hi"'
> $VAR
"hi"
Why is the output of the above commands different?
A similar thing occurs with single quotes:
> VAR="echo 'hi'"
> $VAR
> 'hi'
1
vote
3answers
175 views
man xargs says standard input is delimited by blanks; but is it?
I'm puzzled by what actually defines an arg in xargs.
The man page seems to suggest that args are delimited by blanks (I assume that means whitespace). However the following script doesn't behave as ...
1
vote
1answer
260 views
Escape text for further passing to zenity
I am going to show an error window using zenity:
/usr/bin/zenity --error --text="my error message"
The error text to pass is obtained as output from another application. This output may contain ...
4
votes
1answer
122 views
find usage - command line vs script
I am seeing different results from the find command between being run manually on the command line vs run in a script.
If I run the following on the command line:
find . -name '*.txt' ! -name ...
3
votes
2answers
198 views
issues with GNU tail -f and combination of commands
$ tail -f /logs/filename.log | awk '!(/list)'
I am able to run this command in GNU Linux flavour
But when I written in a script it is not working.
test.ksh:
variable="/logs/filename.log | awk ...
4
votes
1answer
133 views
printing a string's “canonical print-escaped form”
I'm trying to write a function, I'll call it escape, that will behave like this:
% IFS=$' \t\n\000'
% escape FOO $IFS
FOO=$' \t\n\000'
In other words, escape takes two arguments, and then, taking ...
5
votes
1answer
2k views
Remote for-loop over SSH
I have the following in a script
for server in ${servers[@]}; do
echo ${server}
ssh user@${server} "for i in /tmp/foo* ; do echo ${i}; done"
done
But it doesn't work. Weird thing, I see $I amount ...
19
votes
2answers
648 views
Why escape trivial characters in shell script?
I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code:
[ -f $myfile ] && \rm -f $myfile
The escaping backslash ...
2
votes
3answers
279 views
pull out a file named to ~
So I have downloaded a music album from aMule and it is located in the .aMule/Incoming directory. I tried to move it out with the following command:
mv albumName.rar ~
This left me with a file ~ ...
3
votes
1answer
166 views
Mutt: can I define my own rules for quoted message detection?
I recently started using mutt with my gmail IMAP mail address.
Because I loved it so much, I also set it up with my college email address.
This, sadly, is hosted by the college ICT team under ...
2
votes
2answers
210 views
Shell script output incorrectly splitting while being passed as an argument to script
Let's say I have the following two shell scripts:
#!/bin/sh
#This script is named: args.sh
echo 1 "\"Two words\"" 3
, and:
#!/bin/sh
#This script is named: test.sh
echo "Argument 1: "$1
echo ...
5
votes
2answers
638 views
Number of backslashes needed for escaping regex backslash on the command-line
I recently had trouble with some regex on the command-line, and
found that for matching a backslash, different numbers of
characters can be used. This number depends on the quoting used for
the regex ...
11
votes
3answers
2k views
Can't use exclamation mark (!) in bash?
I'm trying to use the curl command to access a http url with a exclamation mark (!) in its path. e.g:
curl -v "http://example.org/!287s87asdjh2/somepath/someresource"
the console replies with bash: ...
1
vote
3answers
465 views
How can we rename a file with semi-colon as part of the filename?
I tried to rename all file with extension "XLS;1" to "XLS" but it just didn't work.
I tried the following in cygwin in windows xp and they don't work:
mv *.XLS;1 *.XLS
mv *.XLS\;1 *.XLS
mv ...
6
votes
3answers
7k views
What characters do I need to escape when using sed in a sh script?
Take the following script:
#!/bin/sh
sed 's/(127\.0\.1\.1)\s/\1/' [some file]
If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
0
votes
1answer
227 views
Shell script to check server state
I am writing a script that would ssh into the VMWare server and check if the VMs are up or not. There's some error in the server=awk "/$i/{print $2}" /home/dharmit/scripts/vmids line. I am getting ...
1
vote
2answers
448 views
Issue with mv command in a script
This must be a very simple issue to solve, but I am stuck (not a UNIX pro). I need to move a gz to a target directory, but I get a No such file or directory.
NOW=$(date +"%Y-%m-%d-%T")
...
2
votes
1answer
2k views
grep and escaping a dollar sign
I want to know which files have the string $Id$.
grep \$Id\$ my_dir/mylist_of_files
returns 0 occurrences.
I discovered that I have to use
grep \$Id$ my_dir/mylist_of_files
Then I see that the ...
4
votes
1answer
327 views
Calling script from bash has problem with arguments
I have a script that generates an xml file and then executes a perl script, passing a series of arguments to it. Here's the key code:
CMD="./dnscurl.pl --keyname $KEYNAME -- -X POST -H ...
8
votes
1answer
995 views
How can I execute `date` inside of a cron tab job?
I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use:
0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log
...
3
votes
1answer
1k views
Bash: Merge foldername from variable with filename
First I write a configfile with all my parameters like this
path="/home/test/"
I name it test.conf.
Then I write a shell script with this content, name it test, and make it executable with chmod ...
1
vote
1answer
313 views
Execute command through SSH
I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra ...
3
votes
3answers
285 views
Escaping argument in bash script?
I'm writing a bash script wherein I want to check that one of the arguments passed to it is a valid group.
I have the line
if [ `grep -c -e '\b$2\b' /etc/group` -eq 0 ]; then
echo "Error: $2 is ...
7
votes
3answers
5k views
What does ` (backquote/backtick) mean in bash?
I came across the following command
sudo chown `id -u` /somedir
And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does ...
2
votes
2answers
370 views
How do I echo a command and include line returns?
I am writing a bash script, and on a condition I'd like to output ps aux --sort -rss
However, when I write :
echo `ps aux --sort -rss`
everything is on one huge line. How do I run it so it outputs ...
2
votes
1answer
134 views
Why does this variable have no value even though it is set in .bashrc?
If I append this:
hi=11
export hi
to the .bashrc and then I su to this user with:
su - bela
then I:
echo $hi
11
Then it's working, the "hi" variable has the value of "11". But. When I:
...
3
votes
3answers
2k views
Why is echo ignoring my quote characters?
The echo command isn't including the complete text that I give it. For example, if I do:
$ echo ' echo PARAM=` grep $ARG /var/tmp/setfile | awk '{print $2}' ` '
It outputs:
echo PARAM=` ...
2
votes
1answer
689 views
sudo -u username -s “cmd arg” returns command not found
I used to execute the command:
sudo -u elasticsearch -s "ulimit -Hn"
and it was returning the value of ulimit -Hn as seen by user elasticsearch until I tried it on Ubuntu 11.10. There it returns:
...