I've been trying to get some practice in with bash shell scripting but I've been having trouble using the $1 variable to reference the first argument for my script. It's a simple script that takes a file as an argument and prints the name of the file. Here's my script:
#!/bin/bash
function practice() {
echo "${1}"
}
while getopts "h:" opt; do
case "$opt" in
h) practice
;;
esac
done
exit 0
I tried the following command:
./practice.sh -h somefile.txt
For some reason it returns an empty line. Any thoughts?