The following script was run through
Shellcheck before posting - to verify I didn't slip up with regards to quoting...
Code:
#!/bin/bash
read -rep "Name: " name
read -rep "Directory: " -i "$HOME" directory
read -rep "Encoding: " -i "UTF-8" encoding
read -rep "Type: " -i "link" type
read -rep "Weblink: " -i "https://" weblink
read -rep "Icon: " -i "text-html" icon
directory=$(readlink -f "$directory")
iconfile="$directory/$name.desktop"
# TODO: insert validation and confirmation
echo "Creating file [$iconfile]"
cat > "$iconfile" <<-eof
[Desktop Entry]
Encoding=$encoding
Name=$name
Type=$type
Exec=firefox $weblink
Icon=$icon
eof
To understand specifics, one may wish to consult "
help read" (or the
read command in Bash manual),
man readlink, and
Here Documents in the
Bash manual.
Validation is left as an exercise to the reader, but it is an important step - not just to check values are correct, but also because it would be annoying to unintentionally enter a non-unique name and overwrite an existing file...