Hello,

I'm brand new at shell scripts and I am attempting to complete a homework assignment but I am not quite sure what I am doing wrong here.

The instructions are
Write a bash script that takes two arguments and generates a nicely formatted, plain-text, manual page for the command denoted by the first argument, stored in the file named after the second argument, with the extension “txt”.

This is for the manual page passwd


Here's my first attempt at a script. Can someone please help me accomplish this and point me to resources that will help me with the syntax of writing scripts?

#!/bin/bash

script
man passwd | col -b
exit
mv typescript MAN_PASSWD_FORMATTED.txt
done

I'm trying to utilize cmds I have learned to accomplish this, however, when I run the script, it will only run the first cmd "script" And I dont even think my script is how he wants it to be, I think im taking the long route here.

Arguments are parameters you pass to functions. Or referring to the command line is what you enter in the shell.
Assuming you have a script that needs two arguments when you run it at the command line you need to provide those arguments. ./script_name.sh argument_one argument_two e.g.
script_format.sh

#! /bin/bash
arg_one=$1
arg_two=$2

man $arg_one > $arg_two.txt

./script_format ls directories will create a file name directories.txt with the formatting man uses.
Of course, it will fail if not arguments are entered, showing that it is always very important to validate variables before using them.

This article has been dead for over six months. Start a new discussion instead.