HEX
Server: LiteSpeed
System: Linux CentOS-79-64-minimal 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: vishn3436 (5293)
PHP: 8.0.15
Disabled: NONE
Upload Files
File: //scripts/script-server/samples/scripts/write_file.sh
#!/bin/bash

set -e

repeats=1
text="I'm called"
filename='simple.txt'
clear=false

while (( $# >= 1 ))
do
key="$1"

case $key in
    -r)
    repeats="$2"
    echo "repeats = $repeats"
    shift # past argument
    ;;
    -t)
    text="$2"
    echo "text = $text"
    shift # past argument
    ;;
    -f)
    filename="$2"
    echo "filename = $filename"
    shift # past argument
    ;;
    --clear)
    clear=true
    ;;
    *)
    # unknown option
    ;;
esac
shift # past argument or value
done

if $clear; then
    echo "Clearing the file..."
     > ~/"$filename"
fi

read -p "Press enter to start writing to the file (~/$filename)"

for (( i=0; i<repeats ; i++ ))
do
   echo "$text" >> ~/"$filename"
done

echo "File content >> \n"
cat ~/"$filename" | grep --color=always -E "$text|$"