Questions tagged [dash-shell]

A POSIX-compliant shell implementation that aims to be as small as possible. Please use the [hyphen] tag instead of [dash] if your question is about the "-" character.

The Debian Almquist shell (dash), a modern replacement for , is a POSIX-compliant Unix shell. It requires less disk space than , for example, but it is also less feature-rich.

Resources

151 questions
67
votes
2 answers

Dash double semicolon (;;) syntax

I'm trying to find a way to run multiple commands in parallel in sh and wait for it completion. I've found that following doesn't work (sh: 1: Syntax error: ";" unexpected): sh -c '(sleep 3 && echo 1) & ; (sleep 3 && echo 2) & ; wait' But this…
valodzka
  • 5,535
  • 4
  • 39
  • 50
50
votes
5 answers

bash, dash and string comparison

I am trying to compare two strings in a simple shell script. I was using /bin/sh instead of /bin/bash, and after countless hours of debugging, it turns out sh (which is actually dash) can't handle this block of code: if [ "$var" == "string" ] then …
LiraNuna
  • 64,916
  • 15
  • 117
  • 140
41
votes
3 answers

equivalent of pipefail in dash shell

Is there some similar option in dash shell corresponding to pipefail in bash? Or any other way of getting a non-zero status if one of the commands in pipe fail (but not exiting on it which set -e would). To make it clearer, here is an example of…
Lavya
  • 1,475
  • 2
  • 17
  • 21
26
votes
4 answers

Arrays in a POSIX compliant shell

According to this reference sheet on hyperpolyglot.org, the following syntax can be used to set an array. i=(1 2 3) But I get an error with dash which is the default for /bin/sh on Ubuntu and should be POSIX compliant. # Trying the syntax with dash…
zoom
  • 1,686
  • 2
  • 16
  • 27
23
votes
3 answers

Redirector "<<<" in Ubuntu?

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?
jmginer
  • 361
  • 1
  • 3
  • 7
22
votes
9 answers

Shell scripting input redirection oddities

Can anyone explain this behavior? Running: #!/bin/sh echo "hello world" | read var1 var2 echo $var1 echo $var2 results in nothing being ouput, while: #!/bin/sh echo "hello world" > test.file read var1 var2 < test.file echo $var1 echo…
Ryan Ahearn
  • 7,886
  • 7
  • 51
  • 56
20
votes
2 answers

Bash script execution with and without shebang in Linux and BSD

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…
GreyCat
  • 16,622
  • 18
  • 74
  • 112
20
votes
4 answers

syntax of for loop in linux shell scripting

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…
mkab
  • 933
  • 4
  • 16
  • 31
18
votes
5 answers

Portable way to check emptyness of a shell variable

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…
hyde
  • 60,639
  • 21
  • 115
  • 176
18
votes
2 answers

Run bash script with sh

I have bash script and it requires bash. Another person try to run it with sh script_name.sh And it fails because sh is symbolic link to dash in his distribution. $ ls -la /bin/sh lrwxrwxrwx 1 root root 4 Aug 25 16:06 /bin/sh -> dash I have an…
user1032985
12
votes
2 answers

What's the best way to embed a Unicode character in a POSIX shell script?

There's several shell-specific ways to include a ‘unicode literal’ in a string. For instance, in Bash, the quoted string-expanding mechanism, $'', allows us to directly embed an invisible character: $'\u2620'. However, if you're trying to write…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
11
votes
2 answers

How to migrate scripts from bash to dash?

I'd like to avoid installing bash on every new Debian 6 install. So I need to convert all my bash scripts to dash. - How would you do that ? - What are the differences between the 2 languages ? - Are you aware of any caveat and pitfall ? - Is it…
dugres
  • 12,613
  • 8
  • 46
  • 51
10
votes
4 answers

How to iterate over the characters of a string in a POSIX shell script?

A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings: for x in $(seq 1 5); do echo $x done But, how do I iterate over each character of a word?
Luis Lavaire.
  • 599
  • 5
  • 17
10
votes
2 answers

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

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…
Motiejus Jakštys
  • 2,769
  • 2
  • 25
  • 30
8
votes
2 answers

how to tell the version number of dash?

I have a dash shell installed as /bin/dash. I checked the manual of dash, which is the same as the POSIX shell manual, and there is nothing there to tell the version of the shell. dash --version does not work. How to tell the version number of…
Mark Galeck
  • 6,155
  • 1
  • 28
  • 55
1
2 3
10 11