How do I execute all the commands in a bash script?

256 Views Asked by At

I want to open a console (Konsole) to (1) request the user enters a filename, (2) create a file with basic content and (3) open the file in a text editor (Kwrite).

If I run the below in file.sh, using "Run in Konsole", it prompts for input, prints the content and opens the new file in Kwrite, all as expected:

#!/bin/bash
echo -n "Enter filename and press [ENTER]: "
read filename
printf '<?php get_header()?>\n\n<?php get_footer()?>' > "$filename".php & kwrite "$filename".php

However when I execute the below version of the script by double clicking on the file to open a console, execution stops after I enter the file name and hit enter.

#!/bin/bash
konsole --hold -e echo -n "Enter filename and press [ENTER]: "
read filename
printf '<?php get_header()?>\n\n<?php get_footer()?>' > "$filename".php & kwrite "$filename".php

Where am I going wrong? It seems "read" is not recognised as a command in the second version when the script opens Konsole.

0

There are 0 best solutions below