Tag Info

New answers tagged

0

Linux Walkthrough of creating a file with dashes and spaces, then removing it. BE CAREFUL! Don't accidentally run a rm -rf / or similar cascade delete command. If your file you are trying to remove includes asterisks or slashes, do not accidentally pump a . or /* or * or some other wildcard which could cascade delete your operating system. Create a ...


6

The backticks (``) are command substitution: they are replaced by the result of running the command inside the backticks. Here they run whoami, which prints your username. The - after su makes su run a login shell: a login shell will read certain environment configuration from scratch, among other things. By default it would just run the user's shell as an ...


1

With zsh: print -r -- **/*.csv(D:a:q) Note that some characters (like newline, tab or non-printable ones) are rendered with the $'...' notation which may be a problem for you. Another approach is: print -r -- *.csv(e/'REPLY=${(qq)REPLY:a}'/) Where all the file paths are single-quoted.


4

For passing file paths as arguments to a command, find does this on its own with its -exec option without any xargs trickery: find /home/user -name '*.csv' -exec yourcommand '{}' + That will find every file called *.csv in /home/user and then execute yourcommand /home/user/a\ b.csv /home/user/my\ dir/c\ d\$2.csv ... with all of the found files as ...


1

This string literal in awk "echo \"select * from abc limit 1;\"| impala-shell|grep -Eo \" a-[0-9]-[0-9]* \| HS[0-9] \| [0-9]* \| [0-9]* \" " represents the following string value: echo "select * from abc limit 1;"| impala-shell|grep -Eo " a-[0-9]-[0-9]* | HS[0-9] | [0-9]* | [0-9]* " Backslash followed by another character which is not a letter or ...


11

Generally, you only have to escape one time to make special character considered literal. Sometime you have to do it twice, because your pattern is used by more than one program. Let disscuss your example: man gcc | grep \\. This command is interpreted by two programs, bash interpreter and grep. The first escape causes bash knows \ is literal, so the ...


1

Try this: $ perl -e "$(cat <<'EOF' print 'qwerty'; EOF )" qwerty You must use double quote for perl to know what program to run, and bash to expand here document. $ perl -MO=Deparse -e "<<'EOF' print 'qwerty'; EOF " '???'; -e syntax OK You can see, perl see your input as string only. With cat and process substitution: $ perl -MO=Deparse ...


2

It's because creating a giant string and passing it as an argument isn't what "here documents" do. They create a stream, which can be connected to some job's input. Concretely, cat <<! foo ! is not equivalent to cat foo . Speaking of cat, it can help us out here. Warning: non- useless use of cat follows! echo $(cat <<! foo ! ) See, we ...


1

I’m not sure what your objective is, but if you’re simply trying to build a Rube Goldberg machine – “a contraption, invention, device or apparatus that is deliberately over-engineered or overdone to perform a very simple task in a very complicated fashion” – then try sh -c 'ls $0' -l or sh -c 'ls $1' supercalifragilisticexpialidocious -l or even sh ...


6

You're interpreting the man page wrong. Firstly, the part about -- signalling the end of options is irrelevant to what you're trying to do. The -c overrides the rest of the command line from that point on, so that it's no longer going through bash's option handling at all, meaning that the -- would be passed through to the command, not handled by bash as ...


1

To complement the great existing answers: If you're using bash and you prefer using actual newlines for readability, read is another option for capturing a here-doc in a variable. With trailing (and leading) \n instances REMOVED ($IFS set to \n): IFS=$'\n' read -r -d '' str <<'EOF' Hello World =========== EOF # Test printf %q "$str" # -> $'Hello ...


2

Place the single quote within double quotes, as follows: sftp> put /path/Dr"'"\ A.tif It would also handle most other special characters as well. If you want to have a single double-quote, then quote the single double-quote within double single-quotes :-) : sftp> put /path/Dr'"'\ A.tif Alternatively, you can escape the single or double quotes: ...


11

You need to quote your variables. Without quotes you are writing test -n instead of test -n <expression>. The test command has no idea that you provided a variable that expanded to nothing. In shell syntax, $VARIABLE outside of double quotes is the “split+glob” operator: the value of the variable is split into a list of whitespace-delimited words, and ...


3

use the escape character \ like this: ./mjpg_streamer -i \"./input_uvc.so -r 320x240\" -o \"./output_http.so -w ./www\"


4

After variable expansion, the command line is normally not re-interpreted. You would need calls to eval for the wanted behaviour. You have actually a XY problem. To avoid code duplications, use a shell function instead: convert_func(){ echo "CP1 $1" > "$2" sudo awk 'BEGIN{printf "<?xml version=\"1.0\" ...


5

You're using double quotes to delimit the string as well as inside the string itself, so the quoted string stops early and your internal quote characters aren't included: sed -i "s|"jdbc:mysql:... Ends here-^ You can escape each of the quotes inside the string: sed -i "s|\"jdbc:mysql://localhost/bajaj\",\"root\", ...


2

There are several syntax problems, one of which is fatal and another which is likely to bite you at some point. By the way, you can use + instead of ; to end the -exec directive; this way gzip will be executed in batches, which is slightly faster. If the value of LOGS_DIR is /somewhere/with/logs, then the following command is executed on the remote host: ...



Top 50 recent answers are included