Option 1: Using a bash script parameter
Create the script like so:
#!/bin/bash
( echo something > "$1".php && kwrite "$1".php ) &
clear
Then, you can call the script passing the file name after the command. The script will then automatically create the file with the content you wish, adding the .php
extension automatically, and open the file in kwrite, while releasing the terminal prompt for you to enter a following command.
$1
in the script is a variable that automatically retrieves the next word on the command line. e.g. if the script is called phpfile
, then the command
phpfile myfile
will create and open the file myfile.php
.
Option 2. Using the read
command
The read
command allows to prompt the user for input at the command line.
#!/bin/bash
echo "Please enter filename: "
read FILENAME
echo something > "$FILENAME".php && nohup kwrite "$FILENAME".php &
clear
nohup
may be useful if you are working from the terminal. It detaches the editor from the terminal processes, so it will not be closed if you close the terminal.
Option 3. Using a graphical tool
Zenity, installed by default in Ubuntu, or Kdialog on the Plasma desktop, allow you to prompt the user for input in a graphical dialog for use in scripts. You invoke these tools in a script. The user input then is placed in a variable. Advantage here is that then you could assign the script to a shortcut key. Then you could summon it with a single keypress to have the Zenity dialog pop up and have the script do its work.
#!/bin/bash
FILENAME=$(zenity --entry --title "Name request" --text "Please enter file name:")
echo something > "$FILENAME".php && nohup kwrite "$FILENAME".php &
clear