I need a .bash script that when ran again runs a different script when clicked. Like a…
- User
I need a .bash script that when ran again runs a different script when clicked. Like a toggle.
- Assistant
Sure! You can create a ".bash" script that acts as a toggle by checking for the existence of a flag file. If the flag file exists, it means the script has been run before and should execute the second script. Otherwise, the first script will be executed, and the flag file will be created for future toggling. Here's an example:
bash#!/bin/bash FLAG_FILE="/path/to/flagfile.txt" SCRIPT1="/path/to/script1.sh" SCRIPT2="/path/to/script2.sh" if [ -e "$FLAG_FILE" ]; then # Flag file exists, so run script2 echo "Running Script 2" bash "$SCRIPT2" rm "$FLAG_FILE" # Remove the flag to toggle back to script1 if desired else # Flag file doesn't exist, so run script1 echo "Running Script 1" bash "$SCRIPT1" touch "$FLAG_FILE" # Create the flag file to toggle to script2 fi