Questions tagged [dash]
The Dash shell, a POSIX-compliant derivative of the Almquist shell used as /bin/sh in Debian, Ubuntu and other Linux distributions
169
questions
6
votes
1
answer
1k
views
Putting "$@" in a local variable in dash
I have a Bash function that does some string manipulation on its arguments as a whole ("$@") by putting it in a local variable, something like this:
my_func() {
local args="$@"
...
1
vote
1
answer
89
views
Anyway to bind keyboard to dash (Debian Almquist Shell)?
Specifically Up/Down for history navigation.
What I already know
I understand dash is a minimalistic, no bloat, (somewhat) strict POSIX shell.
I understand the philosophy behind it, and the reason ...
1
vote
0
answers
178
views
I get permission denied for a command in an sh script, but same command works from terminal
I have a service run by systemctl in RedHat 8.8. The service itself is relatively simple:
cat /etc/systemd/system/myservice.service
[Unit]
Description=My service
After=network-online.target
[Service]...
12
votes
2
answers
11k
views
When sh is a symlink to bash or dash, bash limits itself to POSIX-compliance, so it should be 100% compatible with sh?
From Difference between bash and sh:
ABck to the question: If you have /bin/sh as a link to bash, then bash will not behave the same when called as /bin/sh as it does when called as /bin/bash. When ...
9
votes
1
answer
539
views
Why does exiting with a stored returncode of a nested command result in different returncodes in Dash and Bash?
Running
bash -c 'bash -c "echo test1; exit 1;" &> /tmp/x; buildresult=$?; tail -n 100 /tmp/x; exit $buildresult;'
results in test1 being printed to console and echo $? to print 1 which in my ...
10
votes
6
answers
4k
views
Portable check empty directory
With Bash and Dash, you can check for an empty directory using just the shell
(ignore dotfiles to keep things simple):
set *
if [ -e "$1" ]
then
echo 'not empty'
else
echo 'empty'
fi
However I ...
5
votes
2
answers
632
views
dash maximum variable length under systemd
I have a shell script that uses a single variable as an associative array (one KEY=VALUE per line).
Throughout the execution of the script, the variable is manipulated to add, remove or modify ...
3
votes
1
answer
656
views
Debian /bin/sh in a Docker container never seems to look at .profile
I can not seem to get dash to look at $HOME/.profile:
pedz@Peace:s001 ~[S:hatred] % docker exec -it hatred-web-1 dash -i
# cat $HOME/.profile
PROOF=true; export PROOF
PATH=/hatred/bin:$PATH; export ...
1
vote
1
answer
118
views
dash script replace array
This script works if I use bash on my Debian 11 (bullseye). But now I need to refactor it to use Debian's sh shell(/bin/dash).
#!/bin/dash
var1=1
var2=2
var3=3
arr=($var1 $var2 $var3)
exist_var=&...
7
votes
2
answers
1k
views
How do I keep a dash shell script running despite any error?
I have a dash shell script that is intended to run to the end of file:
#!/usr/bin/dash
# File b_shell
. a_nonexistent_file
echo "I want to print this line despite any previous error."
...
7
votes
2
answers
813
views
Is there a pipefail equivalent for dash?
I have a perl script that runs a system() call to execute shell commands and I would like to run more than one command and pipe data between them. Something like (in perl):
system("command1 | ...
2
votes
1
answer
81
views
How to add a substring to a string as a column
The title may not be the best at describing the issue, but this was the best I could come up with, moving on to describe what I'm trying to do, I use artix runit as my os, and it is tedious to create ...
7
votes
1
answer
609
views
What parts of dash are not part of the POSIX standard?
I know that dash adheres quite closely to the POSIX standard, but I know that it's not 100.00% strict POSIX without any extras. The shell that comes closest/adheres exactly to the POSIX standard is as ...
1
vote
1
answer
8k
views
dash: why am I getting the error "Syntax error: EOF in backquote substitution" when my script doesn't even contain a backquote?
#!/bin/sh --
for set_trap_sig in HUP INT QUIT ALRM TERM; do
trap -- '
trap -- - '"${set_trap_sig:?}"' EXIT || exit "$?"
kill -s '"${set_trap_sig:?}"' ...
3
votes
1
answer
400
views
Why is "${1-"$var"}" (option 6 down below) not mentioned in POSIX?
The only reference I could find in the spec is this:
It would be desirable to include the statement "The characters from an enclosed "${" to the matching '}' shall not be affected by ...
69
votes
7
answers
38k
views
Is dash or some other shell "faster" than bash?
I always thought that the only benefit of using dash instead of bash was that dash was smaller, and therefore many instances of dash would start faster at boot time.
But I have done some research, ...
4
votes
4
answers
1k
views
How to escape the null character in here-document?(bash and/or dash)
I want to perform shuf --zero-terminated on multi-line strings with here-document.
17
votes
3
answers
3k
views
What is the difference between : and true?
In bash:
$ type :
: is a shell builtin
$ type true
true is a shell builtin
Looks like they are the same, but they don't give the same system trace:
$ strace :
strace: :: command not found
$ strace ...
1
vote
1
answer
1k
views
Multiple commands in variable? [duplicate]
Is it possible to execute multiple commands stored in a variable?
Singe command works fine
variable="echo HELLO"
$variable
HELLO
I would like to have something like this
variable="...
2
votes
2
answers
2k
views
Is there an invoked file for dash and sh as non login shells in /etc directory?
/etc/profile can be invoked by sh and dash inside an interactive login mode. Is there any file in /etc directory to be invoked when they are in an interactive non-login mode?
9
votes
2
answers
2k
views
How to find out the version number of `dash` without resorting to package management systems?
I have been using bash most of the time and has just started playing with other shells. I started with dash and tries to find out its version number but the usual method like -v or $version does not ...
7
votes
1
answer
1k
views
Why doesn't sudo always spawn a shell sub-process?
I am trying to understand why some shells seem to receive a special treatment when called with sudo. For instance, there seem to be two possible behaviours:
The "implicit" group (pstree is a ...
2
votes
3
answers
7k
views
Can dash replace bash as my default shell?
From what I read, dash can be made as a shell by using the command
~$ chsh shirish
Password:
Changing the login shell for shirish
Enter the new value, or press ENTER for the default
Login Shell ...
1
vote
1
answer
406
views
Bash for every x files create sub folder and move files there
I am looking for an alternative dash command I can use
as I am trying to execute the code from within python
and due to the fact that the sub folder has 100's of files I am am trying to group into ...
2
votes
0
answers
266
views
how to close file descriptor bigger then 9 by dash in shell script
I want launch a shell script in code called system("sh example.sh"), and close all file descriptors like this:
for fd in $(ls /proc/$$/fd); do
case "$fd" in
0|1|2)
;;...
0
votes
2
answers
1k
views
Sourcing file in dash with . file gives "not found" error
I'm trying to source (bash-parlance) a file in dash using . file as specified by the man page:
. file
The commands in the specified file are read and executed by the
shell.
But I ...
1
vote
1
answer
396
views
SHELLOPTS equivalent for /bin/dash
I have to run a number of shell scripts that are defined by a third party. So I cannot (or would prefer not to) change their content or which shell (bash vs. dash) they are using. They may or may not ...
0
votes
1
answer
123
views
Incorrect order of commands in "Command Substitution" (Bash/Dash)
Why is it that when you run the substitution commands, the order of execution is broken, as in the example below. First the chmod command was executed, then echo 1 and echo 2?
echo $(echo 1; echo 2; ...
0
votes
0
answers
53
views
Secure transfer of arguments to a program (dash/bash)
Transfer via stdin
#!/bin/dash
echo 'password' | program -
Transfer via stdin using an intermediate variable
var_pass=$(echo 'password')
echo $var_pass | program -
unset var_pass
Transfer via ...
1
vote
1
answer
276
views
Proper way to wrap dash using rlwrap
On Ubuntu, I have set alias sh='rlwrap --complete-filenames sh' to get readline keybindings and filename completion when using the dash shell (on my computer, sh is /usr/bin/sh, which is a symbolic ...
-1
votes
3
answers
90
views
Changing the place operator in a csv file
I've been editing a CSV file so I can import it into postgres. At this point I want to change the operator from column 5 to the left side of the column when the value is negative"-". When it ...
0
votes
3
answers
80
views
find/detect file name goups
On fs i have files like:
PREFIX_GROUPNAME_OTHERNAMES[.txt|.*]
eg:
A_ABC_A.txt
A_ABC_B.txt
A_ABC_C.txt
A_XYZ_A.txt
A_XYZ_B.txt
A_XYZ_C.txt
For some futher tasks i want to get the group names.
$# ...
5
votes
2
answers
2k
views
Is there a way to make the local command work portably to dash ksh bash and zsh?
In dash (and in bash zsh and some other shells) the command local works to make a variable scope limited to that function (and descendants in some cases). That enable the possibility of making a ...
2
votes
0
answers
147
views
Can't grep or word count the output of jobs command in dash
This is what I tested in Arch's dash shell and FreeBSD's default sh shell, the results are the same.
$ sleep 100 &
$ jobs
[1] + Running sleep 100
$ jobs | wc
0 0 ...
0
votes
1
answer
242
views
purpose of dashes in `wget -qO- https://get.speedify.com | bash -`
In this command:
wget -qO- https://get.speedify.com | bash -
Source: https://support.speedify.com/article/562-install-speedify-linux
...the first -q is the option for "quiet" mode. What is ...
7
votes
2
answers
846
views
Why does dash's echo expand \\\\ differently to bash's echo?
I have a little open source project that for various reasons I've tried to write in reasonably portable shell script. Its automated integration tests check that hostile characters in path expressions ...
3
votes
1
answer
2k
views
ssh: force different shell for non-interactive command execution
how can I force specific shell to be used for non-interactive command execution via ssh on remote server?
My default shell on the remote server is zsh, but I need to execute given command using /bin/...
5
votes
1
answer
2k
views
/bin/sh: wildcard expansion does not work in script
I am using dash as /bin/sh. In my script, I have following line:
SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.*
Which is supposed to match file /tmp/ssh-abcdefghijkl/agent.1234. Even when the file ...
0
votes
2
answers
528
views
How to execute a one-line posix dash command within dash script to enable coredump?
For unrelated purposes I am forced to produce a script that only works with posix sh.
Within my script I have checked if the system allows the creation of coredumps, then if the limit is set to 0 I ...
3
votes
1
answer
114
views
dash and local keyword not resetting shell
dash shell (unlike bash and busybox ash implementation where both examples print foo: '') takes value of previously
defined variable, i.e. guarding with local does not work:
$ foo=ee; bar() { local ...
-1
votes
1
answer
357
views
Having an interactive shell experience but running everything through dash
So i'm starting to get addicted to POSIX standards and simplicity yet i hate not having autocomplete using the arrows to go through characters and i want a cool shell prompt.
so is there anyway that i ...
0
votes
0
answers
182
views
Why integer division is faster than bitwise shift in shell?
I'm comparing performance of bash and dash (default sh in Xubuntu 18.04).
I expect sh to be faster than bash
I expect bitwise shift to be faster than division operator.
However, I'm getting ...
1
vote
2
answers
210
views
Can't delete multiple files with spaces on name with rm
I'm working on a deploy script for my dotfiles, they are stored on a Git bare repository, from which i git checkout it's files into my home directory, in order to seamlessy do it without thousands of ...
-4
votes
1
answer
3k
views
How to printf ascii characters with hex or dec inside /bin/sh -c '...'?
/bin/sh would be dash
what is the correct syntax for printf to display certain ascii character using hex or dex code in dash?
let's say i want to printf a dollar sign ($). which hex or dec code should ...
0
votes
1
answer
401
views
Global Variables across scripts [duplicate]
Why is lets say HOME recognized by all my scripts but my variable DMENU isn't?
I export it in my bspwmrc file which is executed at start up.Also had it in my zshrc.
Why do this?
DMENU="-h 27 -z ...
0
votes
1
answer
170
views
su not working inside arch-chroot with dash shell
When i try to do the following inside a dash script:
#!/bin/dash
arch-chroot /mnt /bin/dash <<- EOF
su myuser
whoami
EOF
It simply logs the "root", but when i try to do it ...
12
votes
2
answers
4k
views
Shell script returns 0 exit_status despite syntax error
Consider this script:
#!/bin/sh
foo=1
if [[ ! -z $foo ]]; then
echo abc
fi
It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubuntu (...
14
votes
2
answers
7k
views
exit trap in dash vs ksh and bash
Here's a simple script that sets up a temp dir in the current dir and a trap to delete it on exit.
#filename: script
set -x
trap 'rm -rf "$d"' exit
d=`TMPDIR=$PWD mktemp -d`
"$@"
If I do ksh ...
5
votes
2
answers
1k
views
bash -e and && evaluation inside functions
I'm puzzled by bash (and dash) behavior when -e option is set.
Simple example:
#!/bin/bash -e
func() {
false && true
}
false && true
echo "1"
func
echo "2"
...
0
votes
1
answer
229
views
dash: How can I quote the arguments ala "${(q+@)@}" in zsh?
I want to quote the arguments in dash (or sh, or even bash if that's not possible). I can do that with "${(q+@)@}" in zsh, such that reval <sth> ... is the same as just typing in <...