5
votes
3answers
395 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 ...
1
vote
2answers
40 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
60 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
4answers
55 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
33 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 ...
4
votes
4answers
164 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
112 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 | ..| ...
15
votes
2answers
320 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
105 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 ...
0
votes
3answers
64 views

echo bytes to a file

I'm trying to connect my rasberry Pi to some display using the i2c bus. To get started I wanted to manually write stuff, bytes in particular to a file. How do you write specific bytes to a file? I ...
5
votes
4answers
103 views

How to quote a string containing dollar sign $ and single quote '?

My directory's name contains a $ and ', for example :~$ export DIR=\$my\'dir :~$ sh -c "ls $DIR" How can I run above command without $my being expanded? I know the single quote doesn't work since ...
1
vote
1answer
50 views

Assignment to variables

I was trying to devise a solution to a different question asked on the site and came across this curious issue. Here is the set of commands that I issued: $ foo=82a9948422 $ echo $foo 82a9948422 $ ...
13
votes
2answers
2k views

Why can't I do ls *.txt in a subshell?

~$ echo $(ls) arguments.txt cecho.sh Desktop Documents Downloads example.txt Music Pictures Public ~$ echo $(ls "*.txt") ls: cannot access *.txt: No such file or directory Why does the ...
2
votes
2answers
175 views

Do I need to encapsulate awk variables in quotes in order to sanitize them?

As per an answer on stackoverflow, it's my understanding that encapsulating bash variables in double-quotes is a fairly safe way of sanitizing user input. What about awk variables? For example, if ...
2
votes
3answers
70 views

bash adds extra single quotes

I have a problem executing my script. When executing it in debug mode (bash -x), I can see that bash is adding extra quotes. Therefor my script is failing. Here this is within my script: ...
1
vote
2answers
64 views

How do you preserve a space in a literal expression in an array value in bash and how to trim down results from a sort command?

In the context of searching for expressions in log files, I was wondering generally if there was a way to quantify and qualify the contents of the logs in /var/log in some way. In particular, does the ...
2
votes
4answers
118 views

Using a generated list of filenames as argument list — with spaces

I'm trying to invoke a script with a list of filenames collected by find. Nothing special, just someting like this: $ myscript `find . -name something.txt` The problem is that some of the pathnames ...
4
votes
3answers
178 views

Help Shell script to pass variables to rsync

I'm trying to create a simple wrapper shell script for rsync. When I send file names to my script, rsync can never seem to identify the correct location. The file names have spaces in them. I've tried ...
1
vote
2answers
42 views

Escaping blackslash in sed

I am trying to write a sed command to replace a line in a file. The sed replace required the current working directory, which starts making the command a bit messy because of the characters that need ...
0
votes
1answer
38 views

How to escape spaces while using command's output in command line [duplicate]

I want to perform the following command in command line : $ md5sum $(find . -type f) But this would cause problems when it encounter files with spaces in filenames : md5sum: Kaufmann: No such ...
3
votes
2answers
86 views

Expansion of a shell variable and effect of glob and split on it

This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
6
votes
3answers
599 views

Why I can't escape spaces on a bash script?

I'm trying to escape the space char for a path in Bash, but neither using a backslash or quotes works. .sh script: ROOT="/home/hogar/Documents/files/" FILE=${ROOT}"bdd.encrypted" ...
4
votes
3answers
237 views

How do you process an entire command as sudo that involves redirecting or piping?

I am trying to follow what I assume is best practises of using sudo instead of root account. I am running a simple concat file operation such as: sudo echo 'clock_hctosys="YES"' >> ...
2
votes
3answers
239 views

awk print ' char

I want to print: cat file.log | awk '{print nir's $1}' output should be: nir's aaa nir's bbb nir's abc nir's dbc The problem is with the ' in nir's. I also tried: cat file.log | awk '{print ...
0
votes
3answers
139 views

the difference between '..' and “..” when I use ssh usr@ip 'pscp …'

My Server machine run Window,and it installed Cygwin. My Client machine run linux. In Clinent machine.I do this: [sikaiwei@login-1-2 v1.4]$ bash test.sh CHUN~19900405 ...
6
votes
3answers
203 views

ImageMagick on multiple files

I have converted a single file from BMP to PNG with ImageMagick's convert using the command below convert CD\ Front.bmp CD\ Front.png I have many such files, thus I tried: for f in */*.bmp ; do ...
1
vote
3answers
89 views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
0
votes
1answer
54 views

Could not get a command to work with bash -c

I am trying to execute a command to find out which process is listening on a particular port and i cannot get it to work if the command is passed as an argument to bash using bash -c netstat -tnlp ...
1
vote
1answer
110 views

Cat write text with “$” inside

I want to write configuration information to a specific file which has dollar signs ($) inside. That seems to be a problem. Here's what I did: $ cat >> /etc/nginx/nginx.conf <<EOF # For ...
5
votes
3answers
258 views

cp doesn't work in script but works in terminal

Now, this is a strange problem, I have this kind of script: CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" RESOURCES_PATH="${CWD}/resources" PROJECT_NAME="something" ...
2
votes
1answer
57 views

date doesn't accept its own output

What is the option for date to give output in a format acceptable to date --set ? I'm trying to remotely set the date, using the current computer clock of my workstation. ssh user@host sudo date ...
1
vote
2answers
139 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
4
votes
2answers
102 views

Word-splitting when parameter is used within command substitution

What needs to be done to ensure that a parameter containing embedded spaces is handled correctly when used within a command substitution? Perhaps an example will illustrate $ file="/home/1_cr/xy z" $ ...
3
votes
1answer
131 views

How can there be a directory named `~`?

I was trying to test out this buggy/new tool to see how it works, and it prompted me to choose a directory to use for stuff I am doing. From the directory ~/Code/indep, I typed in ...
4
votes
4answers
238 views

How can I grep for a string containing regex metacharacters like $ and '?

I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially: grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" . But it returns no ...
4
votes
3answers
251 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
6
votes
4answers
346 views

What is the difference between echo `date`, echo “`date`”, and echo '`date`'?

What is the difference between these three commands? echo `date` echo "`date`" echo '`date`' I am confused on what the differences actually are. I think that when the ' are around it means that it ...
2
votes
1answer
94 views

Why does copying from a script screw with my files?

I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the ...
12
votes
2answers
337 views

Should I use $* or $@?

Which one of $* or $@ is better to use (in array syntax,command line parameters, etc.) to avoid any bugs/problems in code? Or it does not make any difference?
2
votes
1answer
71 views

Why does backslash get converted to space in echo statement if IFS='\'?

Why is \ is converted to space on setting IFS='\' var="'(]\\{}\$\"" IFS='\' echo $var # '(] {}$"
1
vote
1answer
629 views

bash: export: `--wait': not a valid identifier

When I run git-sh from my terminal it works fine. But I get the following warning. bash: export: `--wait': not a valid identifier What is this and how do I get rid of it?
2
votes
1answer
76 views

How to grep including single quote in a file

I have this line from file.php: 'user' => '', What would be the appropriate command using grep to query the exact line?
1
vote
3answers
180 views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I ...
2
votes
3answers
421 views

Quote a variable in shell script “if” statement

e.g. if [ "$FOO" = "true" ]; then vs if [ $FOO = "true" ]; then What is the different? Seems both of two statements also works.
2
votes
1answer
246 views

Screen escape dollar sign

I'm trying to run a command using screen which contains the dollar sign, but the dollar sign does not get through. screen -d -m echo \$ > test.txt test.txt just ends up being an empty file...
2
votes
2answers
848 views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
12
votes
1answer
903 views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
3
votes
2answers
557 views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
9
votes
2answers
339 views

What is the difference between “*.pl” and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
2
votes
2answers
240 views

Bad substitution inside xargs subshell?

I'm using this command to process PNG files: find . -iname "*png" -print0 | xargs -r0 --max-procs=4 -n1 sh -c 'pngnq -s1 $1 && advpng -z -4 -q ${$1%.*}-nq8.png' - It seems to actually work ...