Tagged Questions
1
vote
3answers
72 views
sed - how to replace a single quote?
This works fine:
sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb
against a source of
@driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click
...
2
votes
3answers
34 views
Can I reload variable in a watch command?
Part of my job involves some data handling. One of the tasks is to 'flatten' a set of directories (which we'll call Dir for now), and copy them to a new location called DirFlat.
This can take a long ...
2
votes
2answers
60 views
Calling bash from sh (dash) with commands read from args, and “Unterminated quoted string”/“unexpected EOF”
Just thought I'd document this: I'm trying something very simple - set env variable in bash, and print it out:
$ bash -c "a=1; echo a$a;"
a
$ bash -c "a=1; echo a\$a;"
a1
Now I'd want this same ...
0
votes
1answer
118 views
shell scripting escaping madness - sending single quotes to subshell
I'm beyond my skill level in getting this to work properly...
#!/bin/bash -x
# mxfbc.sh - mxf video file batch converter
# pass at the command line ...
# (1) the directory to batch convert (typically ...
2
votes
3answers
89 views
Treatment of backslashes across shells
How do echo and printf treat backslashes in zsh, bash and other shells?
Under zsh I get the following behavior:
$ echo "foo\bar\baz"
foaaz
$ echo "foo\\bar\\baz"
foaaz
$ echo 'foo\bar\baz'
foaaz
$ ...
2
votes
2answers
80 views
How do I escape a sub-directory name with an ampersand in it?
Running a kornshell and trying to traverse a directory tree.
Want to cd to a sub-directory named as follows:
-3ab_&_-3dc.img
My question is HOW do I need to escape the ampersand in this name?
...
6
votes
2answers
101 views
When is double-quoting necessary?
The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
3
votes
4answers
136 views
How to print “$” in here-document
How can I echo "$" in a here-doc in bash?
For example, I want to have a file with the content on remote server like $ABC=home_dir.
$ ssh hostname sudo -s <<EOF
echo "$ABC=home_dir" > file
...
6
votes
1answer
122 views
Wildcards inside quotes
This will be an easy one, but in my memories, when shell scripting, using double quotes would allow expanding globbing and variables.
But in the following code:
#!/bin/sh
echo *.sh
echo "*.sh"
echo ...
1
vote
1answer
75 views
How to prevent double escaping?
I'm trying to put a bunch of images together into a pdf. I ran gm convert *.jpg out.pdf and it worked, but the images were not in the right order.
I found that ls -v orders them correctly so then I ...
2
votes
2answers
73 views
Use a parameter in a command argument
I run a find command to search files with a name containing perl:
find /tmp -name '*perl*'
/tmp/perl.pl
/tmp/run-perl-stage.pl
But when I set the perl name in a variable PARAMETER and run the find ...
2
votes
2answers
118 views
Use of quotes in GNU grep regular expressions
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
2
votes
1answer
53 views
Confused about when to escape metacharacters in pathnames
I'm pretty confused about under which circumstances do I need to escape metacharacters in pathnames. Consider the following example:
I'm in the following working directory:
$ echo $PWD
...
9
votes
5answers
327 views
Why do I need to quote variable for if, but not for echo?
I've read that you need double quotes for expanding variables, e.g.
if [ -n "$test" ]; then echo '$test ok'; else echo '$test null'; fi
will work as expected, while
if [ -n $test ]; then echo ...
2
votes
1answer
178 views
Trouble in script with spaces in filename
I've got a script that scp's a file from remote host back to local. Sometimes the file names contain spaces. scp does not like spaces in its file names. For some reason my attempts at handling the ...
2
votes
1answer
195 views
Shell escape characters for sh -c
I need to execute a command with escaped argument(s) using sh -c. I know the string looks pretty ugly but simple ones don't cause a problem.
The output of the echo when passed to sh -c is different ...
2
votes
2answers
68 views
Parameter expansion seems to be missing a piece
I'm currently learning how to write simple scripts and can't get my head around a very simple problem.
I have the following command in my script...
touch ${DIRECTORY}/${FILE}
This command appears ...
3
votes
2answers
118 views
How can I use column to delimit on tabs and not spaces?
I'd like to use Unix column to format some text. I have fields delimited by tabs, but within each field there are also spaces. column delimits on white space (tabs and spaces). How can I make column ...
3
votes
2answers
158 views
Colorizing tail output with sed
How would I go about colorizing the output of tail with sed?
echo "`tput setaf 1`foo`tput op`" works as expected
echo "foo" | sed -e 's/(foo)/`tput setaf 1`\0`tput op`/g' however, does not.
What am ...
2
votes
2answers
105 views
Parameter splitting
I have a bash script that is a simple wrapper around another process:
$ cat ~/bin/s3cmd
#!/bin/sh
trickle -u 80 ~/bin/s3cmd.py $*
$
This works great when the parameters don't contain spaces. ...
17
votes
1answer
648 views
Why doesn't 'find' show this file?
Using find with grep, one can locate files that match a pattern:
# find | grep error
./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html
./error_log
./includes/classes/error_log
However, using ...
0
votes
1answer
129 views
Quotes exercise - how to do ssh inside ssh whilst running sql inside second ssh? [duplicate]
Possible Duplicate:
Quoting in ssh $host $FOO and ssh $host “sudo su user -c $FOO” type constructs
Wrapping a command that includes single and double quotes for another command
I want to ...
0
votes
1answer
61 views
Find and use the path of a file?
I'm trying to find the path of a file and move it.
When I try realpath, it is not useful.
For example : I want to move the file All Hail the Generalist - Vikram Mansharamani - Harvard Business ...
6
votes
2answers
256 views
Why does --text=“$@” only pass the first word?
When I run the following script with some arguments like arg1 arg2 arg3:
#!/bin/bash
zenity --entry --text="$@"
zenity creates an entry dialog with this text: "arg1" whereas I expect "arg1 arg2 ...
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 ...
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
128 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 ...
2
votes
2answers
183 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 ...
2
votes
1answer
191 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 ...
4
votes
2answers
649 views
Passing arguments with quotes and doublequotes to bash script
At this moment I have:
#!/bin/bash
screen -p 'ScreenName' -x eval 'stuff '"'"$@"'"'\015'
echo eval 'stuff '"'"$@"'"'\015'
But when I call my script as:
# script.sh asd "asd" 'asd'
my arguments ...
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
5answers
1k views
bash execute read command from file
After some manipulations, I got the file with commands that I would be glad to be able to execute.
Input file (name of file is inp2.txt):
"02 - Beautiful Emptiness.mp3"
"02 - Come. mp3"
"02 - Go ...
-1
votes
1answer
692 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
1k 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
289 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
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
199 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 ...
2
votes
2answers
213 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 ...
1
vote
3answers
468 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 ...
5
votes
2answers
641 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 ...
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 ...
1
vote
2answers
449 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")
...
1
vote
1answer
318 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
287 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 ...
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
...

