Hello I am trying to create a simple file that reads in a filename and optionally the number of lines to output but I can't get my script to accept the positional parameter that I have assigned to hold the file name. My Code: ##               task_4-1.sh filename [howmany] - optional parameter#### Read a file containing the names of and number of albums of artist in the album collection.# Program will print the N highest lines of Artist with the highest Album count int he collection# Default N is 10 # One arguement for the name of the input file and a second optional line for how many lines to print.#!\bin\bash#Variable to accept the filename will print an error message if this value is left null filename=${1:?missing.}#Optional parameter that controls how many lines to Output to shellhowmany=${2:-10}sort -nr $filename | head $howmanyWhen I try running the code on the commandline with: task_4-1.sh albumnumber.txt 10I get the error message head: 10 no such file or directory. If I switch assigning the parameter to this bracket syntax: filename=${filename:?missing.}Then I get the error message I specified filename: missingDon't know what I am doing wrong here.
Script no accepting commandline input? Positional Parameter help
bash;shell script;files;io;parameter
The only thing wrong is that you are missing the -n option in the last line. This works the way you expected.sort -nr $filename | head -n $howmany