Tag Info

Hot answers tagged

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"


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 ...


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 ...


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 ...


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 ...


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" # ...


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

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)'


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


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.


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 ...


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 ...


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'


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.


2

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


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


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 ...


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 ...


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 ...


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 ...


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

You can also put your commands into a shell file and then execute the shell file with cron. jobs.sh echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log cron 0 * * * * sh jobs.sh



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