New answers tagged

6

You should be able to just escape the pipe use a backslash mv te\|st test Or in your case with the space mv first\ \|\ last first_last If that does not work you can escape all the special characters by warping them with double quotes. mv "first | last" first_last


5

Because when you use just *net* (without any quoting or escaping), it will be expanded by the shell as the (existing) net file/directory in the current directory before the find command run. So the command becomes: find . -name net As you can see it is just matching net, so usbnet.ko will not be matched. Also note that, without quoting and escaping, if ...


2

To use shell variables in awk give them to the awk script using -v awkvariable="$shellvariable" instead of trying to paste them into the script itself, i.e. awk -v d="$domain" '$2==d {print $1, "1.0"} $2!=d {print $1,"-1.0"}' If the script in doing the right thing or not, I don't know, but you might want to use ${domain} rather than $domain in the ...


4

The last item on this line more "file.txt" | awk '$2=='$domain' {print $1, "1.0"} $2!='$domain' {print $1,"-1.0"}' >"$number_domain.txt" is probably intended to be >"${number}_${domain}.txt" corresponding to the two variables which your script reads. It would be nice if your script also ensured that the variables are not empty strings. If they ...


2

There's no need to escape it if you just want an exclamation mark in the prompt. PS1='foobar!' See what happens.


0

This is the completely unquoted version: grep ^\\*\\* test.out. To pass a literal backslash from the shell to grep, it needs to be escaped. This works as long as you have no files in the directory starting with ^\ and containing another backslash.


3

It's not the shell None of the answers so far has touched on the real problem. It would be helpful to explain why it does not work as you expect. grep -i "^**" test.out Because you have quoted the pattern to grep, * is not expanded by the shell. It is passed to grep as-is. This is explained in the manual page[1] for bash[2]: Enclosing characters in ...


7

As you wanted to check the line which starts with ** and ends with ), you can combine two grep operation like this, grep '^*\*' test.out | grep ')$' Or with single grep command like this, grep -E '^\*\*.*\)$' test.out Explanation ^\*\* : match line which starts with ** .* : match everything after ** \)$ : match line which also has ) at the end of ...


2

Other options. You can use sed or awk also $ sed -n '/^*\*/p' test.out $ awk '/^*\*/' test.out To know lines that end with ) use also grep or sed or awk $ grep ')$' test.out $ sed -n '/)$/p' test.out $ awk '/)$/' test.out


13

Use the \ character to escape the * to make it a normal character. grep '^\*\*' test.out Also note the single quote ' and not double quote " to prevent the shell expanding things


0

I cannot explain what exactly fails in your example (so I admit it is some kind of voodoo programming on my side), but this is a fix that (almost -- see below*) works in my bash (Debian): get rid of inside echo; escape $2. Result: echo password | su -c "ps aux | grep verySpecificChain | grep -v grep | /usr/bin/awk '{ print \$2 }' | xargs kill" userName; ...


0

Shell In shell you can use printf: printf "%b" '\x66\x6f\x6f' > file.bin Note: %b - Print the associated argument while interpreting backslash escapes. Perl With perl, it is even simpler: perl -e 'print pack("ccc",(0x66,0x6f,0x6f))' > file.bin Python If you've Python installed, try the following one-liner: python -c $'from struct import ...


0

You don't want to insert literal quotes into the string. You just want to put quotes around the variable. I would do this: #!/bin/bash hw_data=$(/usr/sbin/system_profiler SPHardwareDataType) ram=$(grep Memory: <<<"$hw_data") model=$(grep Model <<<"$hw_data") cpuname=$(grep Processor <<<"$hw_data") cpucores=$(grep Cores: <<&...


4

Your puzzle isn't right about how bash (and the shell in general) parsed the input. In: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" First, bash parse the right hand side of assignment to one long string $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) because double quote can appear inside double quotes. After then, bash ...


8

Once one is inside $(...), quoting starts all over from scratch. In other words, "..." and $(...) can nest within each other. Process substitution, $(...), can contain one or more complete double-quoted strings. Also, double-quoted strings may contain one or more complete process substitutions. But, they do not interlace. Thus, a double-quoted string ...


0

In case someone else comes along for putting a mix of single and double quotes into a file, this is working too: cat > its-shell-programing.txt << __EOF__ echo $'It\'s Shell Programming' echo "It's Shell Programming" echo 'It'\''s Shell Programming' echo 'It'"'"'s Shell Programming' __EOF__ Everything the shell might see as a variable though must ...


1

As has already been answered, a more portable way to use a variable is to quote it: $ printf '%s\t%s\t%s\n' foo bar baz foo bar baz $ l="$(printf '%s\t%s\t%s\n' foo bar baz)" $ <<<$l sed -n l foo bar baz$ $ <<<"$l" sed -n l foo\tbar\tbaz$ There is a difference of implementation in bash, with the line: l="$(printf '%s\t%s\t%...


9

The problem is that you're not quoting $line. To investigate, change the two scripts so they simply print $line: #!/usr/bin/env bash while read line; do echo $line done < "$1" and #!/usr/bin/env zsh while read line; do echo $line done < "$1" Now, compare their output: $ bash.sh input foo bar baz foo bar baz $ zsh.sh input foo bar ...


13

What happens is that bash replaces the tabs with spaces. You can avoid this problem by saying "$line" instead, or by explicitly cutting on spaces.


17

That's because in <<< $line, bash does word splitting, (though not globbing) on $line as it's not quoted there and then joins the resulting words with the space character (and puts that in a temporary file followed by a newline character and makes that the stdin of cut). $ a=a,b,,c bash -c 'IFS=","; sed -n l <<< $a' a b c$ tab happens ...


1

With #!/bin/bash set -f mono app.exe "$@" set -f has no effect because the double-quoted argument array ( "$@" ) undergoes no further expansions. If "$@" contains an argument whose value is *, it will get through to mono app.exe unchanged. The problem is, that the shell calling this wrapper script will want to expand the asterisk, as set +f is the ...


2

Instead of: cmd="cat ${file}" printf '%s\n' "Running command: '${cmd}'" ${cmd} Either pass a fixed command to eval for it to be interpreted as shell code. cmd='cat -- "$file"' printf '%s\n' "Running command: '${cmd}'" eval "$cmd" That will output Running command: cat -- "$file" which is probably not what you want. Or (bash specific) use printf %q to ...


1

You have multiple levels of nested double-quotes. that gets very tricky, very ugly, and very difficult to read and modify. e.g. ` ssh ${OS_USER}@${OS_HOST} \ ". ~/.kshrc; ... ; echo \"export RC_DB_INSTANCE=\\\"\\\$7\\\"\" >> RC_CONV_SET_VARS". (NOTE: i tested that multi-quoted echo with bash -c on my system, and it worked with that but I'...


-1

You will have to "escape" the quotes: echo "export RC_DB_INSTANCE=\"$7\"" will do the trick...



Top 50 recent answers are included