New answers tagged

2

Try using fgrep (or the -F option to grep that does the same), and write your query without escaping the "<" and ">". I'd also suggest using single-quotes ' rather than double-quotes ", since the shell may expand what it think is variables and such when you use double-quotes. fgrep -i 'template <int N>' *


8

Grep interprets \n as a newline character. It looks like your file does not have newline characters, it has \ followed by n. To search for literal backslashes, you must double them: $ grep -o '\\n[^\\]*\\n' o.txt \n29\n \n3 days\n \n59\n \n7 days\n \n99\n \n12 days\n With GNU grep, the output can be easily cleaned up to remove the \n: $ grep -oP '(?<...


4

Try double quotes for the outer ones: sed -i "/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );"


1

That's supposed to be a back-tick. In the online manual for bash "4.3.39(1)-release" it says: Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !. The characters $ and ` retain their special ...


1

Use: runTelnet "`cat test_results.txt`" Enclosing the backticks in quotes will cause the results of the command to be passed to runTelnet as a single argument.


3

Try: runTelnet "$(cat test_results.txt)"


2

With your version of find, the {} in the string is replaced by the file name. It is almost always an error to use {} as part of a string, because the file name is inserted just like that. Here, the file name is used as a shell script fragment. If there's a directory called a'$(touch wibble)' then your command executes the shell code pwd; echo 'a'$(touch ...


4

& is special in the replacement text: it means “the whole part of the input that was matched by the pattern”, so what you're doing here replaces user=&uidX with user=user=&uidXsysuserid.. To insert an actual ampersand in the replacement text, use \&. Another thing that looks wrong is that . in the search pattern stands for any character (...


2

Change it like this: find pictures -type d -links 2 -execdir \ sh -c 'pwd; echo "$1"; zip -vr "$1/$1.zip" "$1" -x \*.zip -x \*.id' sh {} \;


4

That very much depends on the shell. Check your shell manual for details. Also note that some characters are only special in some contexts. For instance, in most shells,* and ? are only special in list contexts, in POSIX or csh-like shells, ~ is only special at the beginning of a word or following some characters like :. Same for = in zsh. In some shells, [ ...


3

1. Escape Escape all of these characters with a \, like this (does not work on newlines/carriage returns): $ echo Use a \"\\\" symbol to escape characters. Use a "\" symbol to escape characters. 2. Double-quote Enclose the whole text in "s, like this: $ var=variables;echo "Enclose text in \"s. You can also use $var in them. `echo Surprise!!!`" Enclose ...


4

if type emulate >/dev/null 2>/dev/null; then emulate ksh; fi In zsh, this activates options that make it more compatible with ksh and bash, including sh_word_split. In other shells, emulate doesn't exist so this does nothing.


-2

m=($f/FLA.*Image.*file.jpg) removed . and everything works fine m=($f/FLA*Image*file.jpg)


2

There are two elements to a better solution: shift (more) quoting Define the function using shift, like this: function build { local cc="$1" local cflags="$2" shift 2 make CC="$cc" CFLAGS="$cflags" "$@" } where we save the first two parameters to local variables, then shift the whole argument array by two; also, quote the "$@" expansion. ...


1

"FLA.*Image.*file.jpg" means literally FLA.*Image.*file.jpg and will not be expanded by ZSH. If you remove the " and add the parenthesis, like this m=($f/FLA.*Image.*file.jpg) the wildcards should then work. You have to explicitly surround the glob pattern with parentheses so that m is an array, otherwise m is a string and globbing is not done.


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



Top 50 recent answers are included