Tag Info

Hot answers tagged

15

while is not a command, it's a shell keyword. Keywords are recognised before variable expansion happens, so after the expansion, it's too late. You have several options: Don't use a variable at all. while true ; do echo Evil Message; sleep 10; done & Use eval to run the shell over the expanded value of the variable eval "$cmd" & Invoke a shell ...


4

sounds like you're not using proper simple quote ('). Try to copy and paste this one: grep -E '( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ' (I have the same error in bash if I copy and paste your script, which use ’ instead of ')


3

You've got too many shells doing some processing in there. Also, using backticks is a bad idea especially when there's going to be backslashes in them. You should use the $(...) syntax instead. sudo -s starts a shell to run the command, but with sudo trying to escape some of the special characters for the shell. You don't want to use that. ssh runs a shell ...


3

Because the \a character is Ctrl+G -- you don't need to escape the character after \n For maintainability, I'd recommend slightly reducing the one-liner-ness of it, and use actual newlines to continue the a command. This also enables the blank line you want. sed -i -e '$a\ \ # Provide apache user permissions to run the ban_ip.sh script as part of ...


2

It works if you quote the command. IFS="/" read -ra PARTS <<< "$(pwd)" for i in "${PARTS[@]}" do printf '%s\n' "$i" done home user1


2

Another option (besides all the good options listed in choroba's answer) would be to run it in a subshell, like this: (while true; do echo Evil Message; sleep 10; done;) & This will cause bash to run another instance of itself running your code, in the background.


2

This looks like a quoting issue. Perhaps the easiest way to debug this is to pass the option --dry-run to parallel: $ parallel --dry-run "awk -F '\t' -v OFS='\t' '$1 { if($3 !~ /needle/){print;} ;}' {} > {}.output" ::: in awk -F '\t' -v OFS='\t' ' { if( ~ /needle/){print;} ;}' in > in.output There you can see that your variables $1 and $3 have ...


2

Use single quotes instead of double quotes, so that backticks and $ don't get interpreted by the original shell: find . -maxdepth 1 -type d -name 'acer' -exec sh -c 'echo {} $(ls {} | wc -l)' \; For the second question, I would put what you want to do into a separate script, that takes the directory name as an argument. Then do: find . -maxdepth 1 -type ...


2

Is there some particular reason to use sed? Why not ... echo -e '\n# Provide apache user permissions to run the ban_ip.sh script as part of mod_evasive\napache ALL=NOPASSWD: /usr/local/bin/scripts-tecmint/ban_ip.sh\nDefaults:apache !requiretty' >>/etc/sudoers The first 'a' of 'apache' is being escaped by the '\' right before it, resulting in your ...


2

I figured it out, it seems something with .gitconfig parser and to solve it we just need to wrap the whole command with double quotes as follow "!sh -c 'git remote add $0 $1; git fetch $0 && git checkout -b $2 $0/$2'"


2

The following will produce wrong results: str2="( 1 + 2 + 3 + 4 + 5 ) / 3 + 5 * 2" expr $str2 The problem is that the shell considers * to be a wildcard file glob and will replace it with a list of files in the current directory. This is not what you want. expr is archaic. A more modern solution would use the shell's $((...)) form for arithmetic: $ ...


1

The ; semicolon starts a comment that terminates your Git alias early hereby making it incomplete at the time Git tries to run the external shell command you aliased. The manual page of the git-config command states that a ; semicolon starts a comment that extends until the end of a line because Git configuration files are written in the INI format.


1

You need to escape the quotes. Think of them as layers of wrapping, in a game of pass the parcel. Each shell unwraps a 'layer'. So: echo "this ; is a semicolon" But if you wanted to run that via ssh: ssh $user@$host echo "this ; is a semicolon" The ssh would unwrap the first layer of the package - sending: echo this ; is a semicolon Which would ...


1

Bash has not added single quotes to the command. The single quotes that you see are added to make displayed command be valid bash syntax. If you see find -name '"*.log"' it means that bash was told to execute this command: find with two arguments -name and "*.log" (the double quotes being part of the argument). It could have been input exactly like this ...


1

When you expand a variable outside of double quotes, as in expr $str2, the following things happen: Take the value of the variable. The result is a string. Split the value into whitespace-delimited chunks.¹ The result is a list of strings. Interpret each element of the list as a wildcard pattern, i.e. globbing. If it matches files, replace the element by ...


1

You could write ls -d */ | while read dir; do echo "$dir: $(ls $dir | wc -l)" done When the filenames are numbered without leading zeroes, you can try ls -d */ | cut -d/ -f1 | while read dir; do COUNT=$(ls $dir | wc -l); echo "$dir: ${COUNT}" ; if [ ${COUNT} -gt 10000 ]; then ls ${dir}/${dir}?????*.ext | grep -v ...



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