I'm making a command, but there is no way to get the command files (known as .command files)
to ask for words.
like confirmations such as:
Continue to make directory? y/n
And commands use to confirm and ask.
.command scripts run in Terminal windows (that is, when you double-click a .command file, it opens a Terminal window, and you can use that window to interact with the script). You can use that to prompt the user and get input; exactly how you do that depends on the scripting language you're using (which is determined by the shebang (starts with #!
) line at the beginning of the script. In bash, you'd do something like:
#!/bin/bash
read -p "Continue to make directory? y/n " makedir
if [[ "$makedir" = [Yy] ]]; then
mkdir somedirectory
fi
In zsh, the syntax for adding a prompt to the read
command is different, and it has a -q
option specifically for y/n questions (that succeeds if the answer is "y" or "Y", and can be used directly in an if
):
#!/bin/zsh
if read -q "makedir?Continue to make directory? y/n "; then
mkdir somedirectory
fi
In other languages, you'd do... whatever you do in that language to prompt for and accept input.