Tag Info

New answers tagged

3

The problem is with your double quotes. Here you don't need to quote those hash keys as they are simple identifiers. From perldoc perldata: In fact, a simple identifier within such curlies is forced to be a string, and likewise within a hash subscript. Neither need quoting. Our earlier example, $days{'Feb'} can be written as $days{Feb} and the quotes ...


0

It is wrapped in single-quotes, so it cannot be expanded. jq -r '.AutoScalingInstances[] | select(.AutoScalingGroupName == "$var1") ... .InstanceId' The key part is the jq command that you are actually only passing a single argument to (notice the long red part of the command). So your pipes are also not taking effect. You can selectively wrap things in ...


1

Variables in single quotes are not expanded. Try this... var2=$(aws autoscaling describe-auto-scaling-instances | jq -r '.AutoScalingInstances[] | select(.AutoScalingGroupName == "'"$var1"'") | select(.AvailabilityZone == "us-east-1a") .InstanceId'); echo $var2


0

-e requires an argument, the code to execute. You can use a string with embedded newlines. This to me is the most readable. Works with ruby, perl, sed ... ruby -e ' 1.upto(10) do |n| p [n, n.even?] end ' You can pass the ruby/perl code to the interpreter via stdin, but then you can't pass any filename arguments, nor can you read data from stdin ...


0

Other way to escape double-quotes (and other special simbols) put all line(s) in single qoutes (if it is absent in your text): sed "s/^\|$/'/g" <sampleMetadata


2

With standard tools chest, sed is a good one: sed -e 's/"/\\&/g' <sampleMetadata


1

It's easier if you spread it out a little: watch -ben5 ' lsof /mnt/unfs && ps -o tty= -p "$(lsof -F p0 /mnt/unfs | sed -e "s/p//")" | xargs -I terms sudo sh -c '\'' printf "\n\33[97;101m%s\33[31;49m%s\33[97;101m%s\33[39;49m\n" \ "GET OUT OF UNFS" " cd ~ " "NOW!" >/dev/terms'\''' It's pretty difficult for me ...


2

You need more quoting when you pass arguments to SSH. Try this: ssh localhost "df -k / | awk '{print \$3/1024/1024/1024}'" 0 0.00623375 Note the \ before $3.


7

You want to use the -s|--protect-args option to rsync. Without it, the part after the : is passed as is to the remote shell so you can use constructs of that shell to build the list to transfer. That way, if you know the remote shell is zsh for instance, you can do: rsync host:'*(.)' there to transfer only regular files. Or with csh/bash/zsh/ksh: rsync ...


2

You need to both quote the path and use a backslash to escape parentheses in the remote path. Either single or double quotes will work. rsync -azR output.mp4 user@server.com:"encoded/somepath/DRRS_\(H264\).mp4" OR rsync -azR output.mp4 user@server.com:'encoded/somepath/DRRS_\(H264\).mp4'


3

Try the below one, I tested this and it is working. You should quote your destination path with ' or " and you should escape the ( and ). rsync -azR output.mp4 user@server.com:'encoded/somepath/DRRS_\(H264\).mp4' UPDATE: Call your script as below, ./sample.sh "encoded/somepath/DRRS_\(H264\).mp4" sample.sh #!/bin/bash rsync -azR output.mp4 ...


3

You can also use pwgen instead of cating and filtering /dev/random: alias mkranddir='mkdir $(pwgen -s 8 1)'


7

Use single quotes instead of double quotes: alias rdir='mkdir -p ./$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 8)/' Now, the statement is evaluated every time the alias is called. With double quotes the statement is evaluated, when defining the alias, therefore static. Also a simpler solution to create a random directory inside the current working ...


1

Putting quotes around some text disables expansions such as wildcards expansion and brace expansion. A logical way to remember this is that they produce a list of words, but contexts such as quotes ensure that the content is a single word. Furthermore you have spurious commas. In a shell script, words are separated by spaces. declare -a ...


0

The simple way to do it is to use single quotes '…' around the string. Single quotes delimit a literal string, so you can put it anything between them except a single quote '. To insert a single quote in the string, use the four-character sequence '\'' (single quote, backslash, single quote, single quote). Technically, there's no way to put a single quote ...


0

sh -c 'echo "\"left'"'"'right\""' OR sh -c 'echo "\"left'\''right\""' will work. Either of the above will pass echo "\"left'right\"" after -c. When you're inside a single quoted string there is no escaping other than closing that string. To pass a single quote, you can either use "'" or \' . The shell will concatenate adjacent ...


0

sudo -u chris sh -c 'echo "\"left'\''right\""'


3

You can just use a here document. su -someuser -c '<&1 >&2 ssh you@machine sh' 1<<\SCRIPT if ! grep 'some spaces or whatever' /etc/somefile then : do something fi #END SCRIPT The solution requires a little fd juggling because you'll need to get past the initial password read from su, and su won't pass on any ...


3

Doing three quotes doesn't help, you just unquote, quote, and unquote again. You also don't need the subshell. What you really want is: su - someuser -c 'ssh someplace "if ! grep \"some thing\" /etc/somefile; then doSomething; fi"' This kind of approach can become unwieldy quickly -- consider just putting a script on your server and executing that. That ...


3

Your best choice maybe passing variable through environment: letter=a p="Task: *$letter" awk -v RS='-+' '$0 ~ ENVIRON["p"]' <file or: p="Task: *a" awk -v RS='-+' '$0 ~ ENVIRON["p"]' <file Using -v var=value, awk will expand escape sequences in value. If you want to pass data as-is to awk from shell, -v var="$shell_var" is not reliable. Using ...


5

You could pass the whole pattern to awk letter=a awk -v pattern="Task .* $letter" -v RS='-+' ' $0 ~ pattern ' text.txt or construct the pattern as a string in awk letter=a awk -v ltr="$letter" -v RS='-+' ' BEGIN {pattern = "Task .* " ltr} $0 ~ pattern ' text.txt Since awk variables are not prefixed with $, you can't embed them inside a ...


1

I had access logs where the dates where stupidly formatted : [30/Jun/2013:08:00:45 +0200] but I needed to display it as : 30/Jun/2013 08:00:45 The problem is that using "OR" in my grep statement, I was receiving the 2 match expressions on 2 separated lines. Here is the solution : grep -in myURL_of_interest *access.log | \ grep -Eo ...


1

One solution to this problem is to evaluate the whole expression so that the quotes inside the string are parsed: eval zenity "$ZEN" By the way, you may also use single quotes in variable definition instead of escaping double quotes: ZEN='--info --text "pure info" --title "get info"' And BTW2, you have missing # in front of !/bin/bash. If you are ...


1

The difference is that the command zenity sees multiple arguments in the first case, and only one (including a lot of spaces) in the second. With the following awk program, you can quickly output what the shell expands the arguments to. As it happens, zsh I could reproduce your problem: % awk 'BEGIN {for (i in ARGV) print "ARGV["i"] =", ARGV[i]}' $ZEN ...


4

It would be a rare situation indeed where you actually need to store a string (in a variable) along with leading and trailing quotation marks which aren't part of the data. It is typically better to post-process. var='two spaces' printf '# "%s"\n' "$var" # "two spaces" ary=( 'two spaces' '$USER' ) printf '# "%s"\n' "${ary[@]}" # "two spaces" # ...


2

I don't think you want the quotes. I think you just don't want to split into fields on whitespace that isn't newlines. Here's how to do that: http://stackoverflow.com/questions/11393817/bash-read-lines-in-file-into-an-array And here's an example $ IFS=$'\n' read -d '' -r -a FOUNDFILES < <(echo -e "very very latest\nsome other line") $ echo ...


2

Even though the variable downloadedFile is logged with the correct path: '/home/user/Downloads/Parks And Recreation - Season 3 - DVDRip-REWARD/Parks.and.Recreation.S03E01.DVDRip.XviD-REWARD.avi' That's evidently not the correct path: it has extra ' characters at the beginning and at the end. You can see that in the error message from ln: ln: failed ...


2

There are several aspects to this question as asked. In the first place, the effects of a quoted assignment might differ from the same assignment statement sans quotes for two reasons: If the assignment contains delimiting syntax tokens (such as ;<> or white-space) then quotes might serve to include these, whereas the unquoted assignment statement ...


8

TEMP="~/Dropbox" The above defines a variable that contains a literal tilde followed by a slash. Because it is in quotation marks, the shell does not expand ~/ to the home directory. Observe: $ echo "quotes=~/" noquotes=~/ quotes=~/ noquotes=/home/john1024/ Thus, if you want ~/ to mean the home directory, then ~/ needs to be outside of quotes. The ...


3

man bash and look for "Tilde Expansion" or in short: an unquoted tilde(~) is replaced with the user's home, which doesn't happen anymore, if it is part of a variable. $ T=~/Downloads $ echo $T /home/zstegi/Downloads $ T="~/Downloads" $ echo $T ~/Downloads


4

The newlines are in the variable. LS=$(ls -1) sets the variable LS to the output of ls -1 (which produces the same output as ls, by the way, except when the output goes to a terminal), minus trailing newlines. The problem is that you're removing the newlines when you print out the value. In a shell script, $LS does not mean “the value of the variable LS”, ...


3

The reason your command is not working is that you are using fancy quotes instead of normal ones. Change all instances of the double quote character from ” to a plain " and it will work as expected. This looks like you copied and pasted from a web tutorial. You might want to report this issue back to the author.


8

You need to double quote it (and you should double quote variables in most case): echo "$LS" But don't use echo to print variables content, using printf instead: printf '%s\n' "$LS"


1

You have an extra backslash in your symbolic link. The actual path is /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl but you created a symbolic link to /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl When you use the text of the symbolic link in the shell, the backslash is interpreted as an escape character, so you get ...



Top 50 recent answers are included