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
1
vote
1 answer

Very different getopts results with different shells

I did some option parsing in a shell script meant to be insourced in dash and bash, and I got some weird results in bash, so I put the essence of the script in: ./getopts : fn() { local verbose opt while getopts "v" opt; do case…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
1
vote
1 answer

bash execute commands as different user with su

I have the most simple issue and I am so not certain what I am doing wrong. I have a simple shell script using /bin/sh inside the script I have the following: exec_as_wwwdata() { if [ $(whoami) = ${WWW_USER} ]]; then $@ else su -s /bin/sh…
Istvano
  • 992
  • 1
  • 12
  • 19
1
vote
1 answer

How to find out the number of files types in a directory

So i am trying to write a script to search through a directory and find the number files with the same type. I tried this: find $directory -type f | file -b $SAVEFILES | cut -c1-40 | sort -n | uniq -c | sort -nr | but the number of how many times…
Adam
  • 99
  • 2
  • 8
1
vote
1 answer

Show function definition in Ash and Dash

In bash, you can use type to show the body of a function, as in bash-4.3$ myfunc() { echo $@ ;} bash-4.3$ type myfunc myfunc is a function myfunc () { echo $@ } How can I display a shell function body in Ash and Dash?
Elifarley
  • 1,310
  • 3
  • 16
  • 23
1
vote
0 answers

set filename tab-completion in dash case insensitive

I’m using dash shell filename tab-completion feature to complete file names.However default tab-completion in dash case-sensitive.How can I force filename tab-completion in dash case insensitive? In bash, I can add "set completion-ignore-case on" to…
shilk
  • 589
  • 5
  • 17
1
vote
3 answers

Avoid subshell from pipe on dash

I have this example code: find "$1" ! -regex "$regex" 2>/dev/null | while read line ; do a="$line" done echo ("$a") # prints nothing because of subshell I need: Workaround for subshell to make $a visible outside (in global scope) To NOT use…
Mára Toner
  • 302
  • 2
  • 16
1
vote
2 answers

How to find PID of an dash-exec command

NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which has this weird exec problem. I have a simple bash shell script on Linux which is used to launch a server process (which I did not write or control) and would like to have…
Petriborg
  • 2,940
  • 3
  • 28
  • 49
1
vote
1 answer

The largest file

I tried to print the largest file in a directory but I can't explain why I get 768 instead of 726491. $DIR is directory and $ext is file extension. My script should work in dash. find "${DIR}" -type f -name "*.$ext" -exec du -a {} + | sort -n -r…
user3463055
  • 121
  • 2
  • 9
1
vote
1 answer

Why does field splitting of WORD not occur in `case WORD in` statement when WORD is a variable?

Shell script: #!/bin/sh a="foo bar" case $a in "foo bar") echo case 1 ;; esac case foo bar in "foo bar") echo case 2 ;; esac Executing this with bash leads to the following output and error. case 1 foo:…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
1
vote
3 answers

Bash and Dash inconsistently check command substitution error codes with `errexit`

I seem to have encountered a very, very strange inconsistency in the way both dash and bash check for error conditions with the errexit option. Using both dash and bash without the set -e/set -o errexit option, the following program: foo() { …
user964843
1
vote
1 answer

Run echo and redirect it to cat with dash shell

I want make one-liner that creates zipped file with python code. However when I run it in Makefile, it uses the default shell (dash). Is the bash$ dash dash$ zip --exclude '.git/*' --exclude '*.swp' --exclude '*.pyc' --exclude 'tool' --exclude…
mastier
  • 872
  • 1
  • 10
  • 22
1
vote
1 answer

What is the purpose of [ x"$1" != x"" ]?

What is the purpose of [ x"$1" != x"" ]? Looking through xdg-screensaver, the very first command that is run: [ x"$1" != x"" ] || exit_failure_syntax The shebang is #!/bin/sh (which is dash for me). I have found similar syntax in other old shell…
Six
  • 5,122
  • 3
  • 29
  • 38
1
vote
1 answer

Regex compatibility across multiple shells

I'm checking correct date format in my bash script with following code: if [[ $variable == [0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] ]] The format should be: YYYY-MM-DD This works well in bash, however I have problems when trying to run it in dash…
querti
  • 77
  • 2
  • 8
1
vote
2 answers

How to test for a character (or string) in a filename in dash

I have a string (a filename, actually) that I want to test whether they contain a character: NEEDLE="-" for file in mydirectory/* do if [NEEDLE IS FOUND IN STRING] then # do something else # do something else …
Roland Seuhs
  • 1,878
  • 4
  • 27
  • 51
1
vote
2 answers

How to use tab separators with grep in ash or dash script?

Task at hand: I have a file with four tab separated values: peter 123 five apples jane 1234 four rubberducks jimmy 01234 seven nicknames I need to get a line out of this file based on second column, and the value is in a variable. Let's…
Peregrino69
  • 255
  • 2
  • 11