Bash/Quick: Difference between revisions
From charlesreid1
(Created page with "==patterns== ===check if root user=== Use <code>$(id -u)</code> to get the UID. the UID will be 0 if the user is root. <pre> if [ "$(id -u)" != "0" ]; then echo ""...") |
No edit summary |
||
| Line 1: | Line 1: | ||
== | ==Defining functions== | ||
=== | <pre> | ||
function dostuff() { | |||
if [[ -f "${DIR}" ]]; then | |||
echo "${DIR} exists!" | |||
fi | |||
} | |||
dostuff | |||
</pre> | |||
==Patterns== | |||
===Check if root user=== | |||
Use <code>$(id -u)</code> to get the UID. the UID will be 0 if the user is root. | Use <code>$(id -u)</code> to get the UID. the UID will be 0 if the user is root. | ||
| Line 19: | Line 31: | ||
==Flags== | |||
{{Programs}} | |||
{{Unix Programs}} | |||
{{Languages}} | |||
[[Category:Bash]] | [[Category:Bash]] | ||
Revision as of 21:30, 9 September 2018
Defining functions
function dostuff() {
if [[ -f "${DIR}" ]]; then
echo "${DIR} exists!"
fi
}
dostuff
Patterns
Check if root user
Use $(id -u) to get the UID. the UID will be 0 if the user is root.
if [ "$(id -u)" != "0" ]; then
echo ""
echo ""
echo "This script should be run as root."
echo ""
echo ""
exit 1;
fi
Flags
| GNU/Linux/Unix the concrete that makes the foundations of the internet.
Compiling Software · Upgrading Software Category:Build Tools · Make · Cmake · Gdb Bash Bash · Bash/Quick (Quick Reference) · Bash Math Text Editors Text Manipulation Command Line Utilities Aptitude · Diff · Make · Patch · Subversion · Xargs Security SSH (Secure Shell) · Gpg (Gnu Privacy Guard) · Category:Security Networking Linux/SSH · Linux/Networking · Linux/File Server Web Servers
|