Tag Info

New answers tagged

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.


0

Discussions on this Q&A (This is not an answer, please do not up or down vote) comment #1 by fpmurphy1 Actually, when looking for vulnerabilities in shell code, the first thing to do is look for unquoted variables. It's easy to spot, often a good candidate, generally easy to track back to attacker-controlled data. Humm, I disagree. The first ...


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'"


0

I'm not sure what you're trying to do, but there's at least one obvious mistake in your script. You have ssh "$(cat); …"$IFERROR"" | … The fragment $IFERROR is not inside quotes, it is expanded by the local shell in order to build the SSH command that is executed. You want to execute echo "$IFERROR" on the remote side, so you need to quote the $ to ...


0

The message you try to exclude is likely a ssh banner. This one is displayed on stderr, that's why the grep -v doesn't work in your script. Just try to redirect stderr to stdin before the grep. It should work. I don't really understand your command, but it would look like this: typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} ...


-1

just write the variable or data needed to a local file and then in the script run an scp command to send the file to the remote server. on the remote server, have a script that will check periodically (via cron) for the file and read it's contents and do whatever you want it to do.


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


0

There are 2 methods i know Use "--" to make rm stop parsing command line options, like this: rm -- --help or you can use / before any symbol you don't want to treat as command like rm /-help though these are repeated.. still wanted to help


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


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


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 ')


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


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


0

Since the question is How can I split the current working directory into an array? (and not “How do I get IFS="something" read -a arrayname <<< $(command) to work?”), I give you saveIFS="$IFS"; IFS=/ PARTS=($(pwd)); IFS="$saveIFS" Yeah, I know; it’s ugly.  I tried IFS=/ PARTS=($(pwd)) And it left IFS set to /, even if I enclosed it in { ...


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


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.


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


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


0

when I'm trying to use this command var1=`sudo -u psoadmin -H -s ssh daill_scp@files.dc1.responsys.net find . -maxdepth 1 -type f -mtime +14 -exec ls -lh \{} \; | awk '{print $5, $9}'|egrep -v '^./upload|^./download|^./archive|^\.'` it is throwing me as find: missing argument to `-exec' You should use this: var1=`sudo -u psoadmin -H -s ssh ...


-1

You can also try to skip the \ before the semicolon or double quote it... It must be some problem with the syntax on your machine (not reading the semicolon), these variations work on mine... if there was nothing found, you would get a different message


0

Try on this way: ...-exec ls -lh {} \;... (remove backslash before curly bracket) Double quotes: var1=`sudo -u psoadmin -H -s ssh daill_scp@files.dc1.responsys.net "find . -maxdepth 1 -type f -mtime +14 -exec ls -lh {} \; "| awk '{print $5, $9}'|egrep -v '^./upload|^./download|^./archive|^\.'`


0

When quoting gets too tough consider using bash functions: myfunc() { awk -F '\t' -v OFS='\t' '$1 { if($3 !~ /needle/){print;} ;}' "$1" > "$1".output } export -f myfunc parallel myfunc {} ::: *.txt


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

Try this: IFS=$(echo -en "\n\b") touch "$yourfile"


0

Try this: $ spam="foo bar" $ touch "$spam" $ ls -l -rw-rw-r-- 1 user user 0 Mar 29 05:14 foo bar



Top 50 recent answers are included