#!/bin/bash
# Print all environment variables to terminal
echo "Printing environment variables:"
printenv
# Save environment variables to a file
printenv > env_variables.txt
# Count number of lines (entries) in file
count=$(wc -l < env_variables.txt)
# Print result
echo "Number of environment variables: $count"
Explanation:
printenv → Displays all environment variables> → Redirects output to a filewc -l → Counts number of lines$( ) → Command substitution#!/bin/bash
# Print script name
echo "Script name: $0"
# Print number of arguments
echo "Number of arguments: $#"
# Print all arguments
echo "Arguments passed: $@"
Explanation:
$0 → Script name$# → Number of arguments$@ → All argumentsExample Run:
./script.sh one two three
#!/bin/bash
# Assign input arguments
folderName=$1
fileName=$2
content=$3
# Create folder
mkdir "$folderName"
# Create file inside folder
touch "$folderName/$fileName"
# Write content into file
echo "$content" > "$folderName/$fileName"
# Display file content
cat "$folderName/$fileName"
Explanation:
$1 $2 $3cat → Displays file contentservice atd status
sudo apt-get install at
service atd start
service atd stop
at 16:15
cp -r $HOME/Documents $HOME/Main
CTRL + D
atq
atrm JOB_NUMBER
at 16:10
mkdir testFolder
CTRL + D
at 16:12
touch testFolder/file.txt
CTRL + D
at 16:14
mv testFolder renamedFolder
CTRL + D
Verify using:
atq
ls
at 16:20
./welcome.sh
CTRL + D
service cron status
crontab -e
* * * * * command
| | | | |
| | | | ---- Day of week (0-6)
| | | ------ Month (1-12)
| | -------- Day of month (1-31)
| ---------- Hour (0-23)
------------ Minute (0-59)
*/2 * * * * cp -r $HOME/Documents $HOME/croMain
crontab -l
crontab -e
*/2 * * * 2 ./script.sh
Explanation:
#!/bin/bash
# Append message with timestamp to log file
echo "Log entry at $(date)" >> log.txt
crontab -e
*/2 * * * * ./log_script.sh
Verify:
cat log.txt
Explanation:
date → Gets current timestamp>> → Appends to filechmod +x script.sh