Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.
1
vote
3answers
67 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
...
5
votes
2answers
90 views
Bash : command line with optional arguments
I'm running this kind of code:
#!/usr/bin/env bash
set -u
exclude1='--exclude=/path/*'
exclude2='--exclude=/path with spaces/*'
exclude3='' # any 'exclude' can be empty
tar -czf backup.tgz ...
2
votes
3answers
78 views
Very strange behavior with grep and IFS
I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character...
This is the script sample :
OLDIFS=$IFS
IFS="\\n"
i=$(grep -ril $1 *)
echo $i
IFS=$OLDIFS
...
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
1answer
35 views
replacement inside parallel command string
I want to download multiple files and save them to the md5 sum of its name:
cat list | parallel -j4 "md5=$(wget -O - {} | tee tmpfile_{#} | md5sum | cut -d ' ' -f 1); mv tmpfile_{#} $md5"
but the ...
4
votes
5answers
113 views
How to use ' in alias?
I have one-line that I want to call using alias.
while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done
I tried to escape ' like \' but it didn't work.
What is the ...
2
votes
2answers
55 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
114 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
79 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?
...
0
votes
1answer
34 views
Reading a path from a nested grep yields “No such file or directory”
Essentially, I have a file containing the path to another file. A single line looks like this.
"/home/self/file"
Now, separately...
> cat "/home/self/file"
blah blah
...
> grep '".*"' ...
5
votes
2answers
99 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
135 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
...
0
votes
3answers
80 views
Is it the de facto to use the grave (`) symbol, followed by a normal apostraphe (') to quote things?
For example, 'foo bar' would be quoted as `foo bar', or ``foo bar''. Is it encouraged or general practice to use this quoting syntax?
6
votes
1answer
121 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
72 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 ...
-1
votes
3answers
285 views
How to tell grep to match special character at beginning of each word [duplicate]
I have certain questions regarding grep.
Why does the following command match '<Hello'?
$ grep -E "\<H" test
Hello World
<Hello
H<ello
What needs to be done to match '<Hello' only?
...
2
votes
2answers
116 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
2answers
94 views
How to pass the output of a script to a command like ls without the output being split?
Suppose I have a script like this:
#!/bin/bash
printf '%q\n' "b c"
Executing the script prints:
b\ c
on the commandline.
Now, being in a directory which contains a file named b c I want to pass ...
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
325 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
119 views
tcsh vs zsh. Escape/control characters
I am having problems running this command to work in zsh:
my_command -u something -s X:^0
The command works right away on tcsh, but on zsh I get:
zsh: no matches found -s X:^0
This made me ...
1
vote
1answer
86 views
Frequent command “template”: remove parameter expansion escape characters
zsh newbie here... I find myself using a handful of long commands over and over again with slightly different arguments. For example:
rsync -havu --progress --rsh='ssh -l mylogin' ...
3
votes
3answers
145 views
Zsh function with su and echo
I'm trying to add a function to my .zshrc that makes adding new USE flags to my /etc/portage/package.use file easier. Normally, I'd have to do
su -c 'echo "net-misc/aria2 bash-completion bittorrent" ...
3
votes
1answer
239 views
mkdir multiple directories with a subdirectory name having space in it
I want to make multiple directories in one go. The problem is that one of the sub directories have a name with a space in it. The directory structure i want to make is as follows.
project
/level ...
4
votes
2answers
172 views
Bash prompt not recognizing Unicode escapes
I'm trying to customize my Bash prompt with Unicode characters and I'm having a bit of trouble. If I try to include a Unicode character like this:
$ echo ☢ | hexdump -C
00000000 e2 98 a2 0a ...
3
votes
2answers
171 views
Read a file and copy to another file
I'm having a issue, I need to copy the file contents and remove a couple of lines if they match the output from a previous command. But so far, I'm having an issue in maintaining the file lines ...
3
votes
1answer
91 views
Escaping quotes for scp
I needed to write a that behaves correctly with nasty (spaces, braces, etc..)
filenames.
scp -rv "$1" shiny:/Volumes/Seagate3To/\"$1\"
This function works, but I don't understand why the quotes ...
2
votes
1answer
186 views
permission denied executing script over ssh
When a web page is loaded on server A i want it to run a script on server B. I can do this with a series of commands from server A by logging into server B and executing the script, but it needs to be ...
1
vote
5answers
162 views
Identify folder in bash
I was trying to learn how to identify only folders within a folder on the main level.
example:
main
-folder 1
-folder 2
-folder 3
I started with this script:
#!/bin/bash
...
1
vote
2answers
127 views
How to scp folders with nasty names using a shell function
I am trying to write a function that I will put on all my machines in order to make it easy to send files at a fixed place on my network.
Here is my script so far. Some folder may have duplicates ...
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
189 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 ...
2
votes
2answers
181 views
Bash: passing braces as arguments to bash function
I love using the following pattern for searching in files:
grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .
I'd like, however, to have this one wrapped into a ...
3
votes
2answers
152 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
128 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 ...
4
votes
2answers
93 views
Is there any reason to escape a dot in a bash filename expansion?
I am working with a bash script that someone else wrote and I see the following line:
cp -v ${LOG_DIR}/${APPLICATION}\.*.log ${ARCHIVED_LOG_DIR}
The files with which it's working are all named ...
1
vote
0answers
68 views
How to make tcsh not insert whitespace in a command that spans multiple lines
Bash does not seem to insert whitespace but tcsh does.
Tcsh
bash-3.2.25$ tcsh -c 'echo $tcsh; echo A\
> B'
6.14.00
A B
Bash
bash-3.2.25$ bash -c 'echo A\
> B'
AB
How can I ask tcsh to not insert ...
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 ...
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
...
0
votes
2answers
110 views
sqlite fts quoting problem
I can do this in sqlite tool:
sqlite> select caption from notes_fts where notes_fts MATCH '"perl install"';
but cannot from the Linux shell i.e., this fails:
user@host:~$ sqlite3 sqldb ...
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!