Search code examples
linuxbashterminallinux-mint

How to add a txt file in the terminal without putting any data in it


I am trying to add a textfile to the desktop and then delete it, i did have the code working to create the file, but now whenever i create it, it then makes me put data into it, whatever i type in the terminal is saved into the created txt file. What i need is for the file to be created and then the user selects another option from the menu.

#!/bin/bash
#
# Script to perform some simple tasks
#
chmod 755 TaskB.sh
while:
do
clear
echo "*********************"
echo "* Tools *"
echo "*********************"
echo "* [1] Install gnome-disk-utility and gparted *"
echo "* [2] Create CET103Demo.txt *"
echo "* [3] Delete CET103Demo.txt *"
echo "* [4] Search BASH *"
echo "* [0] Exit/Stop *"
echo "*********************"
echo -n "Enter your menu choice [0-4]: "
read yourch
case $yourch in
1) *Not yet inserted code* ;;
2) cat > Desktop/CET103Demo.txt;;
3) rm Desktop/CET103Demo.txt;;
4) *Not yet inserted code* ;;
0) exit 0;;
*) echo "Oooops!!! Please select choice 1,2,3,4 or 0";
echo "Press Enter to continue..."; read ;;
esac
done

Solution

  • if I understood you right, try to change

    2) cat > Desktop/CET103Demo.txt;;
    

    into

    2) touch Desktop/CET103Demo.txt;;