0

Is there a way to script any Linux commands to prompt the user for input?

For example:

chage has many options

Options:
  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -h, --help                    display this help message and exit
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximim number of days before password
                                change to MAX_DAYS
  -R, --root CHROOT_DIR         directory to chroot into
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

I like to type in chage and get the above option and allow me to select one. This will help me to remember all the options rather than having to type chage -h every time.

2

Is there a way to script a specific command? Yes. Is there a way to generalize that to all commands? Not that I'm aware of.

That said, something that might help is bash-completion. With that, you can type the command and a - followed by a double tab and see the list of options available.

$ chage --<tab><tab>
--expiredate  --inactive    --list        --mindays     --warndays
--help        --lastday     --maxdays     --root

$ chage <tab><tab>
<list of user names>
0

Zsh has the run-help widget, by default bound to ESCh, that will invoke the respective man page for the command at the prompt; eg.,

chageESCh

will open CHAGE(1).

quitting out of the man page will leave you back at the command prompt, ready to enter your options.

The widget is described in detail in man zshcontrib:

Accessing On-Line Help
The key sequence ESC h is normally bound by ZLE to execute the run-help widget (see zshzle(1)). This invokes the run-help command with the command word from the current input line as its argument. By default, run-help is an alias for the man command, so this often fails when the command word is a shell builtin or a user-defined function. By redefining the run-help alias, one can improve the on-line help provided by the shell.

As the man page notes, this widget is configurable to point to your own helpfiles (defined by HELPDIR), or others provided by the community.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.