I want to have an input mechanism akin to git commit
. When the script is run, it should open an editor to edit a temporary file, use this file as my input, and then get rid of the file.
Asked
Active
Viewed 675 times
2

Atilla Filiz
- 624
- 1
- 6
- 13
2 Answers
1
One solution is with the the builtin read
command.
read -r -p 'Please enter your favorite editor' editor
echo "You have enter $editor"
Now the value is in the $editor"
variable, next step would be to test if there is indeed an editor that is installed or within your PATH.
if type "$editor" >/dev/null 2>&1; then
command "$editor" ENTER_THE_FILE_YOU_WANT_TO_EDIT
else
echo "$editor no such file or directory!" >&2
exit 127
fi
see
help type
help command
The 127 exit status is what the shell will exit if there is no executable, alias, function. have a look at
man 1p exit

Paulo Tomé
- 3,782

Jetchisel
- 1,264