Flag scripts in ubuntu

Tags:

Answer: 1

15 hours ago

Is there a way to create flag scripts in ubuntu that go off when a particular command is executed in the terminal, like for example when I execute

sudo ifconfig wlan0 down

Another script would get executed.

How can I accomplish this ?

Added by: Madeline Bode

Answer: 2

2 hours ago

I'm not sure if what you're asking is possible directly, but here's one option:

Create a bash script

Create a bash script to perform all the tasks you want. Here's an example to help you get started (as for more advanced usage, Google is your friend).

#!/bin/sh
sudo ifconfig wlan0 down
command-to-execute1
command-to-execute2
etc...

Modify that code and save to a file, e.g. wlan-down.sh, then run chmod +x wlan-down.sh and run it with ./wlan-down.sh.

Create alias

If you don't want to remember where the script is located and want to be able to simply run it anywhere, you can create an alias for it.

To create an alias, simply write alias wlandown="/path/to/wlan-down.sh". You should be able to write wlandown in the terminal, and then it will run your script. If you want to store the alias permanently you need to add it to .bashrc in your home directory.

As you can see, combining these two things can give you a powerful, yet simple way to run complex commands with minimal effort.

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9