Beware the Evil Bash Script: How Malicious Aliases Can Hijack Your Shell
This article reveals a mischievous Bash script that redefines common commands and environment variables—such as EDITOR, tab, cat, ls, rm, sudo, clear, and grep—to create unpredictable behavior, data loss, and system shutdowns, and explains how to recognize and neutralize these tricks.
Warning: Do not run this script in a production environment. The script is a Bash shell prank that redefines many aliases, functions, and environment variables, turning a normal shell into a chaotic playground.
Terrible Default Editor
The EDITOR variable is set to rm instead of vi, emacs or nano. Any program that invokes the default editor (e.g., crontab -e) will delete files.
EDITOR is used by system utilities to launch the default editor.
Devious Tab Key
The Tab key is redefined as a backspace, causing characters to be erased when you try to autocomplete.
tset -e sets the erase character to backspace.
Mysterious Exit
Enabling set -e (or set -o errexit) makes the shell exit on any non‑zero command status, leading to unexpected termination.
Cat Becomes True
The cat command is aliased to true, which always returns exit status 0 and produces no output, making file inspection impossible.
Unpredictable ls Order
The ls command is overridden, so its output appears in random order. Options like -f, -r, -S, -t, -u control sorting, but the script disables them.
Directory Vanishing
Aliases such as rm -rf -v are used to delete directories silently, making it seem as if cd fails because the directory no longer exists.
sudo Triggers Shutdown
Running any command with sudo invokes shutdown -P now, instantly powering off the machine and broadcasting the attempted command.
Fork Bomb via clear
The clear command is aliased to a minimal fork bomb, exhausting system resources and freezing the machine.
Random Future Dates
Using date with $RANDOM returns dates far in the future, adding to the confusion.
CD and grep Tricks
Aliases make cd ineffective and grep -n output unpredictable line numbers.
Reversed Logic
Conditions in if, for, and while are negated with !, causing logic to behave opposite to expectations.
Key Binding Chaos
The bind command remaps Enter (CTRL‑J) to backspace, so pressing Enter deletes characters.
Yes Command Hijacked
The yes command is redefined, breaking scripts that rely on automatic affirmative responses.
Vim Becomes Inert
Aliasing vim with +q makes the editor exit immediately without opening files.
Final Remedy
All these mischiefs stem from malicious alias definitions. To restore normal behavior, remove or unalias the offending entries, or invoke commands via their absolute paths.
For a full example, see the original script at https://github.com/mathiasbynens/evil.sh/blob/master/evil.sh and source it in .bash_profile only if you truly intend to prank a colleague.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
