Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Dash is the Debian Almquist Shell, the small, fast POSIX shell that Debian and Ubuntu use as /bin/sh to run boot and system scripts. It descends from Kenneth Almquist's ash, was ported to Debian by Herbert Xu, and deliberately implements little more than the POSIX shell specification — no arrays, no [[ ]], no process substitution — which is exactly what makes it a strict test of portability. Because it starts faster and carries far less code than Bash, distributions reach for it wherever startup time and predictability matter; and because it rejects Bash extensions, a script that runs in Dash will run on almost any Unix shell, from Alpine containers to BusyBox devices. The language still gives you variables, the read builtin, if and case, while and for loops, functions, and $(( )) arithmetic. On XCODX this page runs real Dash in a live terminal, so read pauses for your keystrokes and there is nothing to install; the version is shown in the badge.
#!/bin/sh
# Reads lines until end-of-input (Ctrl+D) and tallies them.
lines=0
words=0
while IFS= read -r line; do
lines=$((lines + 1))
# split the line into positional params to count words, POSIX-style
set -- $line
words=$((words + $#))
printf 'line %d: %d word(s)\n' "$lines" "$#"
done
echo "----"
echo "Total lines: $lines"
echo "Total words: $words"
case $lines in
0) echo "No input given." ;;
1) echo "Just the one line." ;;
*) echo "Read $lines lines in all." ;;
esac
Dash matters most when portability does: writing Docker entrypoint scripts for Alpine images, Debian maintainer scripts, or anything with a #!/bin/sh shebang that has to survive on minimal systems where Bash may not exist. Choose this page to check whether a script secretly depends on Bashisms — paste it in and Dash's errors point straight at the array, [[ ]], or ${var//.../...} that would break elsewhere — and to practice the POSIX subset that textbooks, exams, and portable scripts assume. Working through read loops, case statements, and $(( )) arithmetic here builds shell skills that transfer to every Unix shell. It is a poor fit for anything that leans on interactive conveniences or Bash-only features, and, like any shell, for logic that grows complex enough that a real programming language becomes the safer choice.
Yes. read pauses the script and waits for a line from the terminal, and because this is a live interactive session your typed input goes straight to stdin, exactly as it would over SSH on a real server. Prompts printed with printf appear before the pause. Ctrl+D signals end-of-input, which is how a while read loop knows to stop, and you can also paste input into the Stdin Box.
Dash implements the POSIX shell and very little beyond it, so Bash-only features — arrays, [[ ]] tests, (( )) arithmetic commands, process substitution, and ${var//find/replace} expansions — are not available. In return it is much smaller and starts faster, which is why Debian and Ubuntu point /bin/sh at it. A script that runs cleanly in Dash is highly portable across other shells.
No. The sandbox has no network and no package-manager privileges, so apt-get, curl, and wget have nothing to reach and nowhere to install to. You get Dash plus the basic Unix utilities that ship in the image; anything outside that base set is unavailable and cannot be added. Write scripts that depend only on the shell and common tools.
Almost always because it uses a Bashism that Dash does not implement — declaring an array, using [[ ... ]] instead of [ ... ], writing function name() with the function keyword, or ${var//a/b} replacement. Dash follows POSIX strictly and reports these as syntax errors, which is exactly why testing here catches portability bugs before a script reaches /bin/sh on another system. Rewrite the flagged part with POSIX-equivalent syntax.
No. Every run gets a clean, temporary filesystem, so a file you create with a > redirect or touch exists only for that run and is removed afterward. That is fine for scratch work within a single script; just do not expect anything to survive to the next run. Keep needed data inside the script or its input.
Yes, it is the real Dash shell, not an emulation, so POSIX features behave as the specification says and Bash extensions genuinely fail. A #!/bin/sh shebang documents intent and is good practice, but the page runs your script with Dash whether or not you include one. That makes it a reliable stand-in for the /bin/sh environment on Debian and Alpine systems.
main.shshellread#!/bin/dash
# Dash - Debian Almquist Shell
echo "Hello from Dash!"
echo "Welcome to XCODX Online Compiler!"
# Variables and arithmetic
COUNT=5
echo "Counting to $COUNT:"
I=1
while [ "$I" -le "$COUNT" ]; do
echo " Number: $I"
I=$((I + 1))
done
echo "Done!"