Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.

learn more… | top users | synonyms

5
votes
3answers
397 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
43 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 ...
2
votes
3answers
52 views

Renaming file which got a quote mark ' in its name

I got a little bit of a problem. One client tasked me with the migration of sites from a really old server. Don't know how they got there, but there are files with ' in their names. Is there any way ...
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 ...
3
votes
3answers
57 views

Change the name of a file that contains spaces in the name

I don't know why but when I go to change this file name with mv command it comes up with the error stating not a directory. -bash-4.1# mv {{ THEME SANITIZED }}.hacks.css myomega.hacks.css
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 ...
1
vote
2answers
29 views

Why my tabs are not expanding in TIMEFORMAT?

I need to measure the running time of an application, so I'm messing with TIMEFORMAT in order to print short format with the maximum precision available. From the Bash Refence Manual: TIMEFORMAT ...
1
vote
1answer
63 views

For loop not getting executed correctly over ssh

I have a script in which I am reading from a csv file where it contains SourceIp, DestinationIP,Source Ports, Destination Ports. First I am reading the sourceIp and trying to do ssh over it (I am ...
1
vote
2answers
44 views

Bash script is not working

I wanted to create a script that executes the ls command with the provided arguments. Why isn't it working? I tried running it with for example -R, then it echoes (I echoed the same thing for ...
4
votes
4answers
165 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 ...
0
votes
0answers
12 views

How to concatenate an echoed string to include literal single quotes around a value pulled from MySQL? [migrated]

I've run into a slight dilemma when I try to contain a value from an array of data pulled from MySQL inside single quotes. This would normally be a no brainer, but I run into issues since it's inside ...
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 | ..| ...
3
votes
3answers
267 views

Why can't find -regex match a newline?

Why does this fail? touch "$(printf "a\nb")"; find . -regex './.\n.' I also tried these, none of which work: find . -regextype posix-extended -regex '.\n.' find . -regextype posix-awk -regex ...
1
vote
1answer
25 views

Expansion in zsh prompt

I'm struggling with zsh prompt, trying to convert my bash prompt to zsh hooks. This code should display the current kerberos ticket and update accordingly, but colors don't work, neither does the ...
1
vote
1answer
74 views

Pass bash script arguments in double quotes to php cli script

I am trying to pass arguments to a bash script and then to a php script, I have literally looked at 30+ links, and tried over a dozen examples, and I for whatever reason have not been able to get the ...
15
votes
2answers
323 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 ...
1
vote
1answer
19 views

Proper use of escape characters in desktop file

I have a command with a working .desktop Exec key as follows: Exec=env XDG_CONFIG_HOME=/home/bean/.config/gedit/ gedit %U I would like to use the $HOME variable instead and it works in the terminal ...
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 ...
2
votes
5answers
169 views

Quoting and escaping

I have a shell script, the arguments of which are collected in quote as a single argument and passed to a perl script. /usr/local/API/check_api.sh "-D x.x.x.x -C Test_Internal_Cluster -u user -p pass ...
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 $ ...
1
vote
1answer
23 views

Need to set a variable with “[]”

I have a tcsh script, in which I need to set a variable to this value defining my system type. type=abc project=def sysname=["Linux"] I tried various combinations to escape the [ and " but have ...
2
votes
3answers
62 views

How to alias a command with '

I wanted to make an alias turn caps lock off: python -c 'from ctypes import *; X11 = cdll.LoadLibrary("libX11.so.6"); display = X11.XOpenDisplay(None); X11.XkbLockModifiers(display, c_uint(0x0100), ...
3
votes
1answer
52 views

variable expansion within command substitution over SSH bash 4.X

I want to do this ssh ${w100user}@web100 'ls -l "$(grep "${1}" /etc/pure-ftpd/pureftpd.passwd|cut -d':' -f6)"' Which obviously performs an ssh session to server web100 as w100user and then greps ...
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 ...
1
vote
2answers
54 views

Different behavior of sed with respect to an array and a string in the presence of backslashes

Let the file foo.txt contain foo\\ bar baz xx Why does the following correctly change "foo\\ bar" to "someotherstuff" in foo.txt? sed -i 's/foo\\\\ bar/someotherstuff/gI' foo.txt while this ...
2
votes
2answers
176 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 ...
1
vote
2answers
66 views

Why is my grep + regex not working?

I recently decided that enough was enough -- I was going to learn to use grep fluently. It's been all of three hours and I'm already stumped by this toy problem. I'm currently syncing a RAID5 array, ...
1
vote
1answer
69 views

.bash_profile alias escape quotes?

On the rare occasion I use the command line, I usually forget syntax. This is one of those times. I want to add a simple alias to my .bash_profile but no matter what quote method I use, I get an ...
4
votes
3answers
179 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
39 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
92 views

Command substitution interpreting spaces within quotes as argument separators

I'd like an alias that additionally appends itself to ~/.bashrc, e.g. function tailias { $(echo "alias $1='${*:2}'" | tee -a ~/.bashrc) } I'm using tee to split the command to ~/.bashrc while ...
3
votes
2answers
87 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 ...
1
vote
1answer
30 views

Problematic quotations

#!/bin/ksh typeset FILE_SIZE1=$(stat -f '%z' test.txt); typeset -r BK_STATARGS="-f '%z'" typeset FILE_SIZE2=$(stat ${BK_STATARGS} test.txt); echo without arg var ${FILE_SIZE1} echo with arg var... ...
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
241 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 ...
5
votes
3answers
73 views

how do I set quotes around a variable so that the programs sees them as quote marks

I am trying to get quotes around a variable to make is just like I typed it in the terminal to get this script to work. it shows " quotes around the varibale " but still does not see it as quotes, as ...
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 ...
1
vote
2answers
56 views

double-quoting parameter (representing filename) doesn't help if spaces are contained

When iterating over some filenames double-quoting the parameter does not prevent the filename from being broken: $ mkdir temp $ cd temp/ $ touch a\ b $ for f in $(find .) ; do echo "$f" ; done . ./a ...