dash-shell

Redirector “<<<” in Ubuntu?

一世执手 提交于 2019-11-29 16:43:41
问题 I'm getting this error Syntax error: redirection unexpected in the line: if grep -q "^127.0.0." <<< "$RESULT" How I can run this in Ubuntu? 回答1: if grep -q "^127.0.0." <<< "$RESULT" then echo IF-THEN fi is a Bash-specific thing. If you are using a different bourne-compatable shell, try: if echo "$RESULT" | grep -q "^127.0.0." then echo IF-THEN fi 回答2: <<< is a bash-specific redirection operator (so it's not specific to Ubuntu). The documentation refers to it as a "Here String", a variant of

How can you use pure unset shell builtin? Can you write shell scripts that are immune to tampering?

萝らか妹 提交于 2019-11-29 16:12:22
问题 I mean I want to use unset that is not a shell function itself. If I could do that, I could make sure that command is pure by running #!/bin/sh { \unset -f unalias command [; \unalias unset command [ } 2>/dev/null; # make zsh find *builtins* with `command` too: [ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on If I am using Debian Almquist shell (dash), I think I can rely that \unset is pure. At least I could not define a shell function named unset in dash . Whereas in bash or in zsh I

Portable way to check emptyness of a shell variable [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-11-29 13:18:48
This question already has an answer here: Why do shell script comparisons often use x$VAR = xyes? 7 answers What is the portable and canonical way to test if variable is empty/undefined in a shell script? It should work in all sh-like shells. What I do now is something like: if [ -z "$var" ] ; then ... and for reverse, doing something when variable is not empty/undefined: if [ -n "$var" ] ; then ... And while these work for the scripts I write now, I'd like to know a way, that will work in any reasonably compatible sh -like shell , even on some more obscure environment than a Linux PC with GNU

bash: unable to set and use alias in the same line

南笙酒味 提交于 2019-11-28 07:57:55
问题 I would expect the second line to say foo instead of command not found : $ alias foo="echo bac" ; foo; -bash: foo: command not found $ foo bac $ Why won't the second line say foo ? Tested with the following shells, same behavior: bash 3.2.5 zsh 5.0.8 dash 0.5.9 busybox 1.25.0 回答1: The behaviour you're seeing is described in the Bash Reference Manual (emphasis mine): The rules concerning the definition and use of aliases are somewhat confusing. Bash always reads at least one complete line of

syntax of for loop in linux shell scripting

南楼画角 提交于 2019-11-27 13:37:33
I have a problem implementing a for loop. I get this error when I execute my script test1.sh: 2: Syntax error: Bad for loop variable I don't understand this error. This is my script #!/bin/bash for (( c=1; c<=5; c++ )) do echo "Welcome $c times..." done can any one tell me syntax for for loop in sh(in ubuntu it links to dash shell) shell in ubuntu? You probably run it with sh , not bash . Try bash test1.sh , or ./test1.sh if it's executable, but not sh test1.sh . A standard POSIX shell only accepts the syntax for varname in list The C-like for-loop syntax for (( expr1; expr2; expr3 )) is a

Bash script execution with and without shebang in Linux and BSD

三世轮回 提交于 2019-11-27 08:21:47
How and who determines what executes when a Bash-like script is executed as a binary without a shebang? I guess that running a normal script with shebang is handled with binfmt_script Linux module, which checks a shebang, parses command line and runs designated script interpreter. But what happens when someone runs a script without a shebang? I've tested the direct execv approach and found out that there's no kernel magic in there - i.e. a file like that: $ cat target-script echo Hello echo "bash: $BASH_VERSION" echo "zsh: $ZSH_VERSION" Running compiled C program that does just an execv call

syntax of for loop in linux shell scripting

家住魔仙堡 提交于 2019-11-27 04:04:44
问题 I have a problem implementing a for loop. I get this error when I execute my script test1.sh: 2: Syntax error: Bad for loop variable I don't understand this error. This is my script #!/bin/bash for (( c=1; c<=5; c++ )) do echo "Welcome $c times..." done can any one tell me syntax for for loop in sh(in ubuntu it links to dash shell) shell in ubuntu? 回答1: You probably run it with sh , not bash . Try bash test1.sh , or ./test1.sh if it's executable, but not sh test1.sh . 回答2: A standard POSIX

Bash script execution with and without shebang in Linux and BSD

Deadly 提交于 2019-11-26 17:45:21
问题 How and who determines what executes when a Bash-like script is executed as a binary without a shebang? I guess that running a normal script with shebang is handled with binfmt_script Linux module, which checks a shebang, parses command line and runs designated script interpreter. But what happens when someone runs a script without a shebang? I've tested the direct execv approach and found out that there's no kernel magic in there - i.e. a file like that: $ cat target-script echo Hello echo