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
8
votes
4 answers

How to recognize whether bash or dash is being used within a script?

I'm writing a bash script and it throws an error when using "sh" command in Ubuntu (it seems it's not compatible with dash, I'm learning on this subject). So I would like to detect if dash is being used instead of bash to throw an error. How can I…
Roger W.
  • 327
  • 1
  • 4
  • 15
7
votes
1 answer

Why subprocess.Popen returncode differs for similar commands with bash

Why import subprocess p = subprocess.Popen(["/bin/bash", "-c", "timeout -s KILL 1 sleep 5 2>/dev/null"]) p.wait() print(p.returncode) returns [stderr:] /bin/bash: line 1: 963663 Killed timeout -s KILL 1 sleep 5 2>…
Lehych
  • 166
  • 1
  • 12
7
votes
3 answers

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

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…
jarno
  • 787
  • 10
  • 21
7
votes
2 answers

Portably trapping ERR in shell script

I'm trying to write a shell script that aborts when a command fails and displays the offending line number. set -e trap 'echo "$0 FAILED at line ${LINENO}"' ERR Turned out the trap line does not work with Ubuntu's default shell script interpreter,…
Elektito
  • 3,863
  • 8
  • 42
  • 72
7
votes
3 answers

dash equivalent to bash's curly bracket syntax?

In bash, php/{composer,sismo} expands to php/composer php/sismo. Is there any way to do this with /bin/sh (which I believe is dash), the system shell ? I'm writing git hooks and would like to stay away from bash as long as I can.
greg0ire
  • 22,714
  • 16
  • 72
  • 101
7
votes
7 answers

Add/subtract variables in a really dumb shell

I am writing a shell script which works on my local /bin/sh fine (dash on Ubuntu 13.04), but I unltimately need to run it on a dumb box where I'm getting an error because of an operation on variables: $((n2 - n1 + 1)) doesn't work, I get an error…
wim
  • 338,267
  • 99
  • 616
  • 750
6
votes
2 answers

Bash vs. Dash behavior with the command `echo -ne "hello\n"`

I got different behaviors with the same command echo -ne "hello\n" with bash and with dash. See below : $ bash -c 'echo -ne "hello\n"' hello $ dash -c 'echo -ne "hello\n"' -ne hello Why is that ? I don't understand at all… My system : $…
Quentin
  • 1,085
  • 1
  • 11
  • 29
6
votes
2 answers

Shell script ending with a line containing only a colon?

I'm studying System V init scripts found in /etc/init.d/ in current Debian 7.4.0 wheezy release(But its also present in other, previous, releases). Almost all of them (from existing services) found in that folder end with, basically an empty line…
Ivan Kovacevic
  • 1,322
  • 12
  • 30
6
votes
2 answers

Loop control from within a subshell

I want to use subshells for making sure environment changes do not affect different iterations in a loop, but I'm not sure I can use loop control statements (break, continue) inside the subshell: #!/bin/sh export A=0 for i in 1 2 3; do ( export…
Jellby
  • 2,360
  • 3
  • 27
  • 56
6
votes
1 answer

Does `dash` support `bash` style arrays?

In the dash shell environment I am looking to split a string into arrays. The following code works in bash but not in dash. IFS="" var="this is a test|second test|the quick brown fox jumped over the lazy dog" IFS="|" test=( $var ) echo…
Blackninja543
  • 3,639
  • 5
  • 23
  • 32
5
votes
2 answers

Different result from $((++n)) when running bash vs dash

I'm getting different outputs when running the program in bash and dash #!/bin/sh echo $SHELL n=1 a=$((++n)) echo $n Bash: $ bash shell_test.sh 2 Dash: $ dash shell_test.sh 1
user2373153
  • 51
  • 2
  • 6
5
votes
2 answers

Regression: Exported Bash function lost after going through another process

When moving from Ubuntu 14.04 to 16.04, I've noticed several of my Bash scripts failing due to missing exported functions. I wonder whether this is related to the fixes for the Shellshock bug, even though I simply export -f the functions, and not…
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
5
votes
2 answers

Check for substring in Shell without Bashisms

I'm trying to write a shell script, and in it I have to look for the presence of -32 in a string. Unfortunately I have to do it without using any bashisms as it has to run on computers running Dash. I tried case ${1+"$@"} in *-32*);; but that will…
Mason
  • 89
  • 5
4
votes
1 answer

Ubuntu container can't find shell script

I'm new to Docker, and am trying a simple example of an Ubuntu container that runs a shell script. I'm on Windows 10 with Docker 17.09.0-ce. My shell script is simply: #!/bin/sh echo "hello world!" My Dockerfile is: FROM ubuntu:14.04 WORKDIR…
Alan
  • 3,715
  • 3
  • 39
  • 57
4
votes
1 answer

How to source a dotenv (.env) file in dash?

There are a lot of examples here how to source a dotenv file in bash but has anyone one a method that achieves the same with dash (which is the default shell for minimal Debian installations)? The solution should look like this: $ some foo…
Bastian Venthur
  • 12,515
  • 5
  • 44
  • 78
1
2
3
10 11