command line automation using .sh scripts

Automating Tasks Using .sh Files

Automate tasks using shell scripts and make them accessible from any location in the terminal with the following steps:

  1. Write your script: Create a .sh file (e.g., myscript.sh) containing your commands.
  2. Make it executable: Run chmod +x /path/to/myscript.sh.
  3. Organize your scripts: Place all your .sh files in a dedicated folder, e.g., ~/my_shell_scripts.
  4. Edit .bashrc with Vim: Type vim ~/.bashrc to open .bashrc in Vim. Append export PATH="$PATH:/path/to/my_shell_scripts" to add your script folder to the PATH.
  5. Source .bashrc: Apply changes with source ~/.bashrc.
  6. Execute from anywhere: Just type the script's name (e.g., myscript.sh) in the terminal. Note: extension also needs to be specified.

With these steps, your custom scripts are now accessible from any location in the terminal, making automation seamless and efficient.

Comments