idnan / bash-guide Goto Github PK
View Code? Open in Web Editor NEWA guide to learn bash
License: MIT License
A guide to learn bash
License: MIT License
The syntax described in the guide should also be accompanied by this alternative so that beginners in bash don't face the error function not found
like I did
#!/bin/bash
hello() {
echo world!
}
hello
say() {
echo $1
}
say "hello world!"
Let me know if you need a PR for this I would be happy to do it ๐
quoting rules really need to be addressed
specifically:
A basic usage of find
The output of sort example.txt | uniq
isn't quite right. Given the input file, it should be:
a
b
c
d
Hello @Idnan
Thanks for making such awesome bash guide, i really liked it.
Please add .deb package installation command dpkg -i
to install the .deb packages by command line.
Thanks.
Instead of using this to demonstrate export:
$ export
SHELL=/bin/zsh
AWS_HOME=/Users/adnanadnan/.aws
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LESS=-R
$ echo $SHELL
/usr/bin/zsh
let's omit zsh
, which is an alternative to bash
. That's confusing, and at cross-purposes with this tutorial.
I suggest updating that part of the README to this:
$ export
AWS_HOME=/Users/adnanadnan/.aws
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LESS=-R
$ echo $AWS_HOME
/Users/adnanadnan/.aws
Thank you for sharing, I am deeply inspired. I'd like to introduce you to an online programming platform called codigger. This platform provides a rich programming environment and resources that are especially suitable for infrastructure engineers like you to script, debug, and share. I cordially invite you to give codigger a try. If you have any questions or suggestions during use, you can contact us at any time, and we will try our best to provide you with help and support.
There should be at least an introduction saying that the presented binaries (grep, find, mkdir ...) aren't part of bash and can be used by any other shell or programming language and are just part of unix commonly used binaries. Just let them know this isn't Bash specific.
Bash builtins should at the contrary be highlighted (export, cd ...) to be differentiated from the binaries.
There is an other use of for
, it's very useful in some case
for char in {a..z}; do
echo$ char
done
It will be print a b c ... x y z
or
for i in {{a..m},{0..9},{n..z}}; do # don't have any space between commas
echo $i
done
It will be print a b c ... k l m 0 1 2 ... 7 8 9 n o u ... x y z
I think it's worth mentioning that some of the function works on Bash 4+.
I'm pretty certain about ${string^^}
etc. not sure about the other functions.
I think that specifying the working version will be super beneficial to mac users (with bash 3) that might get a little disappointed to find some things work differently on their machine.
First of all, thanks for the amazing bash summary!
I think I found a problem with the first for loop example.
It is not working as intended:
for x := 1 to 10 do
begin
statements
end
Testing on Ubuntu 16.04 and cygwin results in this error:
-bash: syntax error near unexpected token `:='
A logical replacement would be:
for x in {1..10}
do
echo $x
done
Write some ln
usage to give reader a basic introduction of it.
This command is used to see the list of running jobs in background (or stopped with a ctrl+z)
I see two issues with your for loops section.
Instead of this:
for name [in list]
do
statements that can use $name
done
How about doing it this way:
for name in one two
do echo $name
done
Example output:
one
two
Anther for loop example:
more list.txt
one
two
for name in $(more list.txt)
do echo $name
done
Example output:
one
two
Currently a user of the can't just cut and past the code into there terminal to run. This way they can do that to test and learn how it works.
Also maybe add a read line section to the while loop section.
Example:
more list.txt | while read line
do
echo "$line"
done
This kind of loop is good for varibles with spaces in.
I can do a pull request if you want and do it for you, just let me know.
The if
part that if [expression]; then
should be if [ expression ]; then
. There must be space after [ and before ]see the link
And it will be better if there is an example given.
Users often encounter difficulties when searching for files within the repository due to case-sensitive filename searches. For example, if a user attempts to find a file named "ReadMe.md" but searches for "README.md", the case sensitivity of the search command will result in a failure to locate the file. This issue can cause unnecessary confusion and hinder productivity.
Example Scenario
Consider the following situation: A user is trying to locate all PNG files in their home directory but forgets the exact casing of the filenames.
Current behavior using find:
$ find /home/user1 -name '*.png'
If the filenames are actually in uppercase (e.g., IMAGE.PNG), the above command will not return any results, leading the user to believe that the files do not exist.
Suggested Improvement
To alleviate this issue, it is recommended to use the -iname option instead of the -name option with the find command. The -iname option performs a case-insensitive search, thereby improving the user experience and ensuring that files are found regardless of their casing.
Recommended Command
Instead of:
$ find /home/user1 -name '.png'
Use:
$ find /home/user1 -iname '.png'
This command will successfully locate files like image.png, IMAGE.PNG, and Image.PNG, regardless of their case.
Hi, i just added translation to Indonesian (Bahasa Indonesia): https://github.com/papua-opensource/bash-guide
The title is self-explanatory, how can I do so in any directory?
Hi,
The guide is awesome, will be very useful for a beginner. (y)
bash shell builtin help
is missing in the guide.
$ help
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
job_spec [&] history [-c] [-d offset] [n] or history -anrw [filename] or hist>
(( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]...>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x command [args]
: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or ki>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callb>
bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-> popd [-n] [+N | -N]
break [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
caller [expr] pwd [-LP]
case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N ncha>
cd [-L|[-P [-e]] [-@]] [dir] readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C cal>
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] or readonly -p
compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G > select NAME [in WORDS ... ;] do COMMANDS; done
compopt [-o|+o option] [-DE] [name ...] set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilnrtux] [-p] [name[=value] ...] source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ...] test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [name ...] times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [arguments ...]] [redirection ...] true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or export -p typeset [-aAfFgilrtux] [-p] name[=value] ...
false ulimit [-SHabcdefilmnpqrstuvxT] [limit]
fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command] umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMANDS; done unset [-f] [-v] [-n] [name ...]
for (( exp1; exp2; exp3 )); do COMMANDS; done until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name () { COMMANDS ; } variables - Names and meanings of some shell variables
getopts optstring name [arg] wait [-n] [id ...]
hash [-lr] [-p pathname] [-dt] [name ...] while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }`
And also Info utility
info
These things help a user to know where to find what he/she needs.
Maybe the search for commands will be more easy if we change to alphabetical order.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.