Simple unit script

Hello guys this is my first post in this forum. Since now ive been passive an ive only been looking for existing information. Now I could use specific help on a UNIX script i want to make that would:

  1. Take 1-3 arguments.
  2. Display the contents of its arguments, formatted as follows:
    � Separator line
    � Filename
    � Separator Line
    � File content
    � Separator line
  3. Display an error message, in case the arguments are less than 1 or more than 3.

How can i do that? i'm so confused.:confused::confused::confused:

Hello,

Could you please be more clear on your requirement. Please share input and expected output with use for same. Also please make sure you are using code tags as per forum rules for code and commands please.

Thanks,
R. Singh

If you're writing your script in Bash shell, you can handle the arguments like this:

#!/bin/bash
#
#

# check command-line for correct usage
if [ $# -eq 0 ] || [ $# -gt 3 ]
then
    echo "Usage: ${0##*/} <arg1> <arg2> <arg3>"
    exit 1
fi

Each argument will be stored in it's own variable: $1, $2, $3.

After checking the number of parameters. One way is with a here document:

for file in "$@"
do
cat << EOF
------------------------------------------
$file
------------------------------------------
$(cat "$file")
------------------------------------------
EOF
done

or

for file in "$@"
do
  printf "%s\n" "------------------------------------------"
  printf "%s\n" "$file"
  printf "%s\n" "------------------------------------------"
  cat "$file"
  printf "%s\n" "------------------------------------------"
done

--
@in2nix4life : that code will work with any POSIX shell, not just bash...

in unix script code with commands like read and cp and chmod

It is all shell script. Is this homework?

yes it is and i've missed some classes and I dont know that basic stuff

Well, that was clever!

Anyhoo...

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.