Hot answers tagged

29

There are two problems with your example. The primary one is that you're assuming that regular expressions work the same as glob patterns in that * is a wildcard meaning "any sequence of characters." In regular expressions, * means "any number of the previous atom" instead, so fil* means f followed by i followed by zero or more l characters. You need to say ...


5

When you write $PGWA without quotes, this splits the value of PGWA at whitespace¹. Quote characters have no special meaning there, so you end up with the words -o, ProxyCommand="ssh, gateway1, nc, %h and %p". See Why does my shell script choke on whitespace or other special characters? for more explanations. A variable expansion outside of double quotes is ...


4

You can either escape the $ sign: rm -r .\$EXTEND or use single quotes: rm -r '.$EXTEND'


4

You're not actually running a bash command. What you're doing is running an executable directly and passing it arguments. Try the following script to see what is happening: import subprocess p = subprocess.Popen(["echo", "a", "b", "|", "rev"], stdout=subprocess.PIPE) print p.communicate() The output will be: ('a b | rev\n', None) There's no ...


3

You don't need the names to be quoted, you need the variables to be quoted. Specifically, to make your script work, you need to replace the for folder in ... loop with: /tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" -l | while IFS= read -r folder; do /tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" ...


3

Your line: psql -U postgres -d ebay_sold -c "UPDATE test_table SET title = regexp_replace(title, '"', '', 'g')" is the problem. You open a double-quoted string at "UPDATE, but it is closed earlier than you think it is, causing you to attempt to run the following as SQL: UPDATE test_table SET title = regexp_replace(title, ' This is clearly not valid. ...


2

Backquotes delimit a command substitution: the command inside the backquotes is executed, and its output is interpolated into the command line. (There are further complications if the backquotes are not inside double quotes, more on this later.) So what's happening is that git rev-list … is executed in the current directory, before RepoScan runs. It can't be ...


2

I would recommend putting those commands into a script that you remotely call with ssh. Otherwise you'd need to put the whole "remote" part of the command line into quotes and properly escape everything inside. This can be tedious and error prone. That's why remote script call.


2

It might be easier to simplify the command so that you have fewer special characters on which the shell might choke: ssh jboss@myTargetServer 'ps -p $(cat /var/run/jboss-as/jboss-as-standalone8.pid) -o %cpu= 2>/dev/null' The trailing 2>/dev/null throws away the error text in the event that the PID file either cannot be found or contains a stale PID. ...


2

You could use: fg_normal=$(echo -e "\033[0m") fg_yellow=$(echo -e "\033[1;33m") or with tput: fg_normal=$(tput sgr0) fg_yellow=$(tput setaf 3)


2

To differentiate a variable from a string bash uses $. When you do : rm -R .$EXTEND variable $EXTEND is expanded and the result is substituted. Inorder to remove .$EXTEND file you need to tell bash to interpret $ without its special meaning. You can do it two ways : rm -R .\$EXTEND #\ strips the special meaning of $ or rm -R '.$EXTEND' # Use single ...


1

The second command as you have it runs the code part ($()) in local subshell. You need to make it run on the other side by escaping special characters (basically $): ssh jboss@myTargetServer tmpValue=\$(cat /var/run/jboss-as/jboss-as-standalone8.pid) \ && top -b -U jboss -n 1 |grep \$tmpValue |awk '{print $9}' or put it all into the apostrophes ' ...


1

The second single quote terminates the first single-quoted string 'echo {}; awk '. Then {print $1} is unquoted, and then there is another single-quoted string ' {} | uniq'. This should be clear in any editor with syntax highlighting; it's also clear if you look at the syntax highlighting in your question. Here the simplest approach would be to avoid nested ...


1

One example: $ echo jeff > jeff $ echo not > not $ echo 's/jeff/not/' | sed -i -f - * $ cat jeff not For more information on what standard shells should do with filename/pathname expansion (globbing), see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_06 where it says: After field splitting, if set -f is not ...


1

So it seems like there are extra quotes being inserted around the contents of noquotes.txt, but not around quotes.txt. This is just Bash being helpful. You'll notice it will put quotes around things whenever there's a symbol that would otherwise be interpreted by Bash. It acts just like you would, using quotes only when necessary. Try to put any of the ...


1

Change ligne=`cat /var/log/svlog | grep "\$day"` to ligne=$(grep "$day" /var/log/svlog) To feed the contents of $ligne to awk, use echo "$ligne" | awk ...


1

The shell does not handle quoted quotes the way that you want. (Once the quotes are quoted, they are treated like regular characters.) You can trick bash into doing what you want. To start define an associative array: declare -A s s=( ["a"]='-search;a params;-search;other a params;' ["b"]='-search;just these params' ) As you can see, the string has the ...


1

The line in your code weka $1 ${search["$1"]} is being subject to shell spliting. If you have not changed the variable $IFS that splitting will happen on spacetabnew line. The line gets expanded to: weka $1 ${search["$1"]} weka a -search "a params" -search "other a params" But getting split as described above, this is what it means: <weka> ...



Only top voted, non community-wiki answers of a minimum length are eligible