You have a bash script in /home/user/
and the bash script is myscript
you can set an alias to run
/home/user/myscript
#!/bin/bash
echo "WELCOME BASH"
Run chmod +x /home/user/myscript
create an alias
and execute by alias name
Temporary alias
— run this in the terminal
alias myscript="/home/user/myscript"
Permanent alias
in ~/.bashrc
(/home/user/.bashrc) — add/edit this to your .bashrc
file
alias myscript="/home/user/myscript"
Now run in terminal: myscript
Option 1
Add this to your bashrc:
alias myscript="source /home/user/./myscript"
or
alias my_script="source ./my_script"
Run my_script
, to run source ./my_script
This work only for your user account. If you want the alias for all users, you will need to add the alias to the system-wide shell configuration file /etc/bash.bashrc
for bash
or ask the administrator to add it.
Option 2
Login to your jenkins server and navigate to the job configuration page for the job you want to use the source command
In build section of the job configuration, add a new build step of type Execute shell
In Command field, define a function that wraps the source command
Example:
function my_source() {
source ./home/user/my_script
# or
source /home/user/./myscript
# or
source /home/user/myscript
}
Assign this function to an alias temporary or permanent
alias my_alias='my_source'
Option 3
Create a wrapper script
#!/bin/bash
source /home/user/my_script
Make the file executable
chmod +x my_script
now you can run ./my_script
Check if the script is located in the same directory as the original script, or in directory that is included in your system PATH variable
Option 4
when the Jenkins job tries to run ./my_script
, it will actually run source ./my_script
with this.
Create a symbolic link to your script:
ln -s $(realpath my_script) source
When Jenkins job run ./my_script
, it will run source ./my_script
from the symbolic link you created
Use this with caution, clean up the symbolic link after you done the job with
rm source
Sources:
alias script_name="source /home/user/./script_name"
in your bashrc ? – Z0OM Mar 31 '23 at 10:10