Tag Info

New answers tagged

0

I guess the (or one if there are many) problem is this line: inputs=${@:4:$len} If $len is bigger than 1 then this converts an array slice into a string and there the word splitting problem arises. possible solution If should work if the above line is changed to inputs=("${@:4:$len}") and this for f in $inputs to for f in "${inputs[@]}"


-1

You have to set the following code before any working files in your script: SAVEIFS=$IFS IFS=$(echo -en "\n\b") Then when you want to exit from your script, you have to do it: $IFS=$SAVEIFS


2

Technically, you don't need to quote the left-hand side within [[ ... ]]. But as St├ęphane Chazelas put it in comments on his beautiful answer, there's no compelling reason not to quote it, so just do it and sleep better at night. It's a good recommended practice, less doubts and questions asked. In old-style [ ... ] you must quote, you don't have a choice. ...


4

Highly recommend You should read this wonderful answer for more details. Setting IFS contains digit can break your code: $ IFS=0 $ echo test $ [ $? -eq 0 ] && echo done bash: [: : integer expression expected Some shells may inherit IFS from environment (dash, ash), some don't (bash, zsh, ksh). But someone can control the environment, your ...


0

Inside the backticks, a backslash quotes the next character. So you're getting the output from the command ssh -q ${SIDHost} ". /usr/vmmc/bin/oracle_scripts/useq $ThisSID; echo $HOST_IS_ERPDB" You need \\ instead: ERPTest=`ssh -q ${SIDHost} ". /usr/vmmc/bin/oracle_scripts/useq $ThisSID; echo \\$HOST_IS_ERPDB"` so that ERPTest is set to the output of ...


-1

In your .desktop file write: Exec=sh -c 'java -jar "$HOME"/.minecraft/Minecraft.jar' Sample 2: Exec=sh -c "u=%u; k=%k; c=%c;"' kd="$k"; [ -f "$kd" ] && kd=`dirname "$k"`; cd "$kd"; uxterm -bg blue -fg cyan3 -fn 9x15' Explanation: All terms like double-quote, quoting, meta-chars (like $ and ~) are always s h e l l - r e l a t e d - the shell ...


1

It seems a common workaround to execute sh, which will resolve the special symbols and variables correctly: Exec=sh -c "java -jar ~/.minecraft/Minecraft.jar"


2

It's nothing to do with SSH. The -x argument to bash is that of bash's set command, which displays the command's arguments in expanded form. This is why the double quoted strings are displayed as single quoted strings. $ cat test.sh echo "here are 'some single quotes' inside double quotes" $ bash -x test.sh + echo 'here are '\''some single quotes'\'' ...


3

While an alias is one way to do it, this can be done with eval as well - it's just that you don't so much want to eval the command execution as you want to eval the command declaration. I like aliases - I use 'em all the time, but I like functions better - especially their ability to handle parameters and that they needn't necessarily be expanded in command ...


12

To be able to time a subshell, you need the time keyword, not command. The time keyword, part of the language, is only recognised as such when entered literally. Even entering "time" won't work let alone $TIME (and would be taken as a call to the time command instead). You could use aliases here which are expanded before another round of parsing is ...


2

Use an array since that can expand to a variable number of arguments: #!/bin/bash # This is file caller.bash switch=() if [[ ${1-x} == x ]] then switch=("--abc=long argument") fi some_command.sh "--exclude=*~" "${switch[@]}" arg Or you could use the ${var+...} syntax: #!/bin/sh # This is file caller.sh unset switch if [ "${1-x}" = x ] then ...


2

String interpolation causes this. There are a number of ways to selectively prevent this from happening. The bash hackers wiki has some good examples, though the specifics may vary if you're not actually using bash. In short, you can prevent interpolation with single quotes, or you can escape the characters. [me:~/work]$ export foo=bar [me:~/work]$ echo ...


4

You're mixing character classes (a list of characters inside square brackets) with the smb.conf share names which are surrounded by square bracket literals. Also, the echo command is not well-formed: in the case where sed exits with a non-zero status, the shell will attempt to invoke the command Failed. A few suggestions: Remove the character class (outer ...


2

The simplest answer is to escape the [ so that it isn't treated as a special pattern character. (The closing ] is treated literally if it isn't preceded by an unquoted [.) test=$(echo \[asdf])


3

Don't use backticks, use $(). Use single quotes around literal strings and double around variables, so echo "$test". Don't use echo, use printf. After all: $ test="$(printf '%s' '[asdf]')" $ printf "%s\n" "$test" [asdf]


5

Option -0 of xargs means that output from pipe is interpreted as null terminated items. In such case you also need to create input for the pipe with find ... -print0.


6

Simple use: find . -size +1M -delete If you insist using xargs and rm with find, just add -print0 in your command: find . -size +1M -print0 | xargs -r0 rm -- Other way: find . -size +1M -execdir rm -- {} + From man find: -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline ...


0

Here's everything you need to know about quoting something to protect it from shell expansion and word-splitting: Enclose everything other than apostrophes between apostrophes. For example, do not becomes 'do not'. Use backslashes to escape apostrophes, i.e. ' becomes \'. Break your string up into apostrophes and other characters, apply the preceding 2 ...


0

I'm going to accept derobert's answer because it gave me information I needed. I still had issues, which I think might of been my awk command, which I replaced with an alternative approach. The following is what I did to ensure my authorized_keys file on the remote server had only unique entries: ssh root@10.100.10.26 "sort /root/.ssh/authorized_keys | uniq ...


3

Try this (I tested on my machine and it appears to work---well, I didn't have any duplicates to remove, but...): ssh root@10.100.10.26 "awk '!seen[\$0]++' /root/.ssh/authorized_keys > /root/.ssh/authorized_keystemp" Your "-quote attempts didn't work since you didn't backslash the $ in $0, leading it to be expanded to something like bash. Your ...


39

Preamble First, I'd say it's not the right way to address the problem. It's a bit like saying "you should not murder people because otherwise you'll go to jail". Similarly, you don't quote your variable because otherwise you're introducing security vulnerabilities. You quote your variables because it is wrong not to (but if the fear of the jail can help, ...


2

Remove the \ from before the space. An escaped space is used to stop the shell splitting at spaces. As you are using a file to list your excluded directories and files then the words Mendeley Desktop will never pass through the shell and therefore will not need escaping. If you were listing them on the command line with --exclude then you'd need to escape ...


4

You have to escape ! to prevent csh/tcsh from performing history expansion. They still do history expansion though you wrote ! in single quote. Try: sed ':again;$\!N;$\!b again; s/{[^}]*}//g' file Or you can write a script an call with -f script.sed (Read sed FAQ).


-1

I am not familiar with tcsh but this sounds like a history expansion problem. In bash single quotes prevent history expansion, maybe in tcsh they don't. You may disable history expansion (I don't know how to do that, though; in bash this is done by set +H). Another option: Backslash escapes should work. Try sed_code=":again;\$\!N;\$\!b again; ...



Top 50 recent answers are included