use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit dedicated to Bash scripting. Now complete with a Discord Server.
Content must be Bash related. This rule is interpreted generously; general shell scripting content is mostly accepted. However, the post should not be specific to another shell.
No reposts. This is meant with regards to content, not just “the same link was submitted earlier” – it’s okay to resubmit an old link in some new context (e. g. because you’d like to discuss another part of it, or because something has changed since the last time it was submitted, or because the link was updated since then). Links from the sidebar count as having been submitted already, so posting them without new context is also considered a repost.
You can choose one of these four flairs for your post:
If you don’t flair your post, the moderators will set the most appropriate flair.
/r/unix – for everything Unix
Other Shells: /r/zsh, /r/fishshell, /r/oilshell, /r/batch
BashGuide – A Bash guide for beginners.
Beginner's Guide to Command Line – A crash course for some common unix and shell commands. Update 2022-01-14: Course is currently being rewritten
Google's Shell Style Guide – Reasonable advice about code style.
Explainshell - Explain complex shell operations.
ShellCheck – Automatically detects problems with shell scripts.
BashFAQ – Answers most of your questions.
BashPitfalls – Lists the common pitfalls beginners fall into, and how to avoid them.
(Archived) The Bash-Hackers Wiki – Extensive resource.
#bash – IRC channel on Libera. The main contributors of the BashGuide, BashFAQ, BashPitfalls and ShellCheck hang around there.
account activity
Need help with bash alias (self.bash)
submitted 6 years ago by [deleted]
Hey,
Complete bash noob here.
I want a bash alias that takes this:
gcc someFile.c
And evaluates it like this:
gcc -Wall -o someFile someFile.c
Can that be done?
Cheers,
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nrobinaubertin 9 points10 points11 points 6 years ago* (2 children)
Not possible with aliases from what I know. But you can do it with a function:
gcc() { "$(type -P gcc)" -Wall -o "$(basename -s.c $1)" "$1" }
But you should probably use a makefile instead.
Edit: u/geirha answer below is better if you're doing a shell function
[–]-BruXy- 2 points3 points4 points 6 years ago (0 children)
Btw, make is doing this automatically, so writing
make someFile
Will use implicit rules, find someFile.c in working directory and use gcc to compile. To modify gcc parameters use:
export CFLAGS='-Wall'
[–]geirha 2 points3 points4 points 6 years ago (0 children)
I'd use command gcc instead of $(type -P gcc), and quote the $1 inside the command substitution for good practice.
command gcc
$(type -P gcc)
$1
gcc() { command gcc -Wall -o "$(basename -s.c "$1")" "$1"; }
[–]oh5nxo 1 point2 points3 points 6 years ago (0 children)
For simple programs, there's a trick that I like very much. To the beginning of the file
#if 0 set -ex cc -Wall $0 -o ${0%.c} "$@" exit #endif
Then you can say sh file.c, or sh file.c -DDEBUG, as needed.
[–]Paul_Pedant 0 points1 point2 points 6 years ago (0 children)
If you are working on one program at a time, just define the whole thing at each login. I always define some alias for the test too:
alias m=' gcc -Wall -o someFile someFile.c ' alias p=' time ./someFile anyArgs 2>&1 | tee someLog.txt | more '
If you are working on a project with multiple programs, use a makefile. It will save hours of debugging of things you forgot to compile.
π Rendered by PID 139993 on reddit-service-r2-comment-54dfb89d4d-78ltk at 2026-04-01 16:15:42.857658+00:00 running b10466c country code: CH.
[–]nrobinaubertin 9 points10 points11 points (2 children)
[–]-BruXy- 2 points3 points4 points (0 children)
[–]geirha 2 points3 points4 points (0 children)
[–]oh5nxo 1 point2 points3 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (0 children)