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

learn more… | top users | synonyms

-1
votes
1answer
51 views

How to grep and treat meta character as normal character?

I am trying to recursively find some pattern which contains meta character. Pattern that I searching for is template <int N> I have tried : grep -F -lir "template <int N>" * # ...
7
votes
1answer
132 views

How to extract the string between two \n in a file

I have a file with pattern <span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
2
votes
1answer
60 views

Why do my single quotes vanish on substitution with sed

What is the right command for: sudo sed -i '/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );' /var/www/html/wp-config.php The result is: define( WP_MEMORY_LIMIT, 64M ); instead of the desired: ...
22
votes
4answers
37k 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 ...
-4
votes
1answer
49 views

What can single quote mean specially within double quotes? [closed]

From bash manual Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘‘’, ‘\’, and, when history expansion ...
1
vote
2answers
42 views

Quoting the output of a backtick command [duplicate]

I'm trying to run an expect script that runs a telnet session to automate the sending of an email, I'm trying to pass the contents of a file as a single argument to my script but when the backticks ...
3
votes
2answers
46 views

Problem with spaces when used in find command

I'm trying to place a zip file with the content of the directory in each directory that doesn't contain any subdirectory. The following command works if there's no space in dirnames and/or filenames ...
2
votes
1answer
50 views

using sed with ampersand (&)

i'm using sed to find and replace patterns within SAS files i have rather than changing them individually. The problem is I am trying to replace macro variables and when i use the ampersand it is not ...
4
votes
2answers
78 views

How to use a special character as a normal one?

Many questions like 'How to type the double-quote char (")?' are being asked, and we don't want to clutter our community with the same answer (Type it as \" if not enclosed in 's, " if enclosed in 's.)...
3
votes
1answer
25 views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[...
0
votes
2answers
75 views

Wildcard not working in quotes

The script is supposed to loop over subdirectories and match all the filenames (FLA.*Image.*file.jpg and FLA.*Image.jpg) in subdirectories and process it. It also create output folder inside the ...
0
votes
1answer
37 views

how to properly pass _set_ of parameters with spaces into shell function

My problem is not simple passing parameters with spaces (I know how to achieve that), consider more complicated case: function build() { make CC="$1" CFLAGS="$2" $* # $* is not correct here! } ...
88
votes
3answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
58
votes
4answers
4k views

Why is 'ls' suddenly wrapping items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them ...
28
votes
5answers
39k views

Parenthesis in expr arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
1
vote
1answer
59 views

How do I rename files that have '|' in them?

I am using Fedora 24. I have tried many different ways to do this. I've tried it under a Windows VM with the folder in question as a shared folder. I've tried using the 'rename' command. I've ...
1
vote
1answer
71 views

Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]

On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
3
votes
2answers
72 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
60
votes
5answers
79k views

What does ` (backquote/backtick) mean in commands?

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 ...
3
votes
1answer
20 views

How can I escape an exclamation point in the PS1 environment variable?

It is substituted with the history number even if I try to escape it with a backslash.
8
votes
5answers
673 views

How to find lines that begin with **

I need to find if any lines in a file begin with ** . I cannot figure out how to do it because * is interpreted as a wildcard by the shell. grep -i "^2" test.out works if the line begins with a 2 ...
2
votes
2answers
45 views

Command behavior is different when executed by an other user (via su -c)

I want to kill every processes who match a specific chain. Here is my script, which works pretty well: echo `ps aux | grep verySpecificChain | grep -v grep | /usr/bin/awk '{ print $2 }'` | xargs kill ...
52
votes
3answers
26k 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 ...
3
votes
3answers
1k 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
70 views

Curl a string with whitespaces and characters in it? [duplicate]

I'm trying to create a "simple" script that I'm going to use to create some documentation for Unix/Mac machines. I've successfully received the information I need, but it seems like I can't send it ...
6
votes
4answers
17k 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
2answers
374 views

nested double quotes in highly-voted one-liner

A StackOverflow answer with > 3.5K votes features this one-liner for assigning to DIR the directory of the current bash script: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" I'm ...
7
votes
3answers
6k views

How to echo `single quote` when using single quote to wrap special characters in shell?

I'm reading shell tutorial today from http://www.tutorialspoint.com/unix/unix-quoting-mechanisms.htm In which it mentions: If a single quote appears within a string to be output, you should not ...
37
votes
1answer
10k 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 $...
67
votes
3answers
12k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
4
votes
2answers
11k 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\ (...
10
votes
4answers
998 views

Why does cut fail with bash and not zsh?

I create a file with tab-delimited fields. echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input I have the following script named zsh.sh #!/usr/bin/env zsh while read line; do <<&...
6
votes
1answer
970 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: s/cid:image002\.gif@01CC3D46\.926E77E0/https:\/\/...
2
votes
1answer
34 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
175
votes
5answers
380k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
1
vote
1answer
74 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...
0
votes
2answers
56 views

To include double quotes within a string

My command is X=`ssh ${OS_USER}@${OS_HOST} ". ~/.kshrc ; ulimit -c unlimited ; cd ${OS_PATH}/NEW_BL1_RC_RATE/bin/conf; echo "export RC_DB_INSTANCE=$7" >> RC_CONV_SET_VARS"` $7 should ...
2
votes
0answers
720 views

How to pass multiple commands via pssh and multiple xterms

I'm attempting to open multiple xterms and run a command as an SAP user via sudo using pssh. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in the servers ...
48
votes
4answers
17k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
100
votes
3answers
63k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
4answers
66 views

execute command over ssh connection [duplicate]

I want to excecute the following command over a ssh connection: tmpValue=$(cat /var/run/jboss-as/jboss-as-standalone8.pid) && top -b -U jboss -n 1 |grep $tmpValue |awk '{print $9}' This ...
4
votes
2answers
7k views

Error with a file name containing parentheses

when I tried to change file name from old.file(1).gz to new.file.gz, It says syntax error, I am using ubuntu 12.04. mv old.file(1).gz new.file.gz bash: syntax error near unexpected token `('
3
votes
1answer
111 views

Syntax error with variable containing quotes

I have a bunch of Linux machines behind 2 gateways. To connect to set one I do ssh -o ProxyCommand="ssh gateway1 nc %h %p" machines_behind_1 ssh -o ProxyCommand="ssh gateway2 nc --proxy %h %p --...
0
votes
3answers
77 views

How do I remove a dot dollar no name directory

I have this weird directory in Oracle Linux that I cannot remove, cannot change owner, cannot change group, etc. It seems to be an environment variable that is empty and is named: .$EXTEND Here's ...
2
votes
1answer
35 views

How to get a list to be entered in quotes

firstly I am a total n00b with scripting, so please forgive any incorrect terminology. I have a simple script that runs a python script (used to deduplicate emails via IMAP) after a user has entered ...
1
vote
3answers
45 views

Unable to use a escape sequences in a variable in a sed command

I'm using sed to highlight a column in the output of a ps command, and it works fine if I hard code the color code. However, the color needs to be dynamic, so I tried moving it to a variable, and ...
2
votes
2answers
112 views

Why won't this bash command run when called by python?

The command $ find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat uses GNU Parallel to print all the .txt files under ~/foo/. I have a python script where I want to call this bash ...
0
votes
1answer
44 views

globbing and wildcards

Are wildcards ever supposed to be expanded for a program that is not the first in the pipeline? Every example uses wildcard for the first program in the pipelilne. For example, the following does ...
0
votes
3answers
80 views

Right syntax for awk usage in combination with other command inside xargs sh –c

How to make this command work: ls * | xargs -I {} sh -c 'echo {}; awk '{print $1}' {} | uniq' It should do the simple thing: print for each file in the folder its name and uniq values in the first ...
2
votes
1answer
25 views

Why is a daily .zshrc reload required using an alias containing $(date -u +%Y%m%d)? [closed]

Each morning I run the following command that tails a log file created daily: ssh -t server@55.555.55.55 tail -f development/abc/$(date -u +%Y%m%d).log This works just fine and each morning the log ...