Question: UNIX BASH Scripting Hello, I'm just starting out and this is literally my first shell script. I'm using vi and can create and save and

UNIX BASH Scripting

Hello, I'm just starting out and this is literally my first shell script. I'm using vi and can create and save and implement the file, but really not sure what it's supposed to look like. Any help will get a thumbs up.

Write a shell script called fileInfo.sh that: - Accepts a filename as an argument. If a filename is not given, exit with an error message. - Outputs the type of the contents of the file (hint: use file, but you may need one of the parameters) - Outputs first line and the last line of the file.

UNIX BASH Scripting Hello, I'm just starting out and this is literally

My script so far. It doesn't work. Throws a syntax error, near unexpected token 'newline"

I don't know how to debug this. help.

my first shell script. I'm using vi and can create and save

Write a shell script called fileInfo.sh that: - Accepts a filename as an argument. If a filename is not given, exit with an error message. Outputs the type of the contents of the file (hint: use file, but you may need one of the parameters) Outputs first line and the last line of the file. Example output: $ ./fileInfo.sh Usage: /fileInfo.sh $./fileInfo.sh /home/useri/.bashrc The file /home/user1/.bashrc contains: ASCII text Here is the first line: # -/.bashrc: executed by bash(1) for non-login shells. Here is the last line: export PATH=$PATH:/home/useri/.local/bin For the first/last lines, your output may differ slightly than this example. #!/bin/bash if [[ ! "$#"-eq 1 ]] #Checking for argument then echo "Usage: ../fileInfo.sh exit i else filename=$1 echo $filename filetype=$(file ${filename}) echo "The $filename contains: $filetype" echo "The first line. head -n 1 ${filename} echo "The last line. tail -n 1 ${filename}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!