Skip to content

Instantly share code, notes, and snippets.

@tymoshenko
Forked from megawertz/bashsnippets.sh
Created September 24, 2018 17:15
Show Gist options
  • Save tymoshenko/41306e46f878842db4f5f92dd2e38fa3 to your computer and use it in GitHub Desktop.
Save tymoshenko/41306e46f878842db4f5f92dd2e38fa3 to your computer and use it in GitHub Desktop.
Some basic bash snippets I use to introduce shell scripting to my Linux class.
#!/bin/bash
# viewing environment variables
echo "The value of the home variable is: "
echo $HOME
# issue a command
echo "The output of the pwd command is: "
pwd
# that's boring, grab output and make it readable
echo "The value of the pwd command is $(pwd)"
# assign command output to a variable
output=$(pwd)
echo "The value of the output variable is ${output}"
# view data on the command line
echo "I saw $@ on the command line"
# read data from the user
echo "Enter a value: "
read userInput
echo "You just entered $userInput"
# concatenate userinput with command output
echo "Enter a file extension: "
read ext
touch "yourfile.${ext}"
# check to see if a file exists
if [ -d /etc/sysconfig ]; then
echo "That file is there and a directory"
else
echo "Not there or not a directory"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment