I have git cloned a number of tools into my HOME folder. Now as there are many of them and my query files are located on a different directory, what I need is make a programme executable from everywhere in the SHELL. I have read this thread but how about Perl and Python scipts. For example, I have a script.pl or script.py file in a folder named scrips. What should I do to make that script run from everywhere?
You can actually place (install) the executable file in /usr/bin/ or even /usr/local/bin/. Of course, you've manually installed the program at that point; your distribution isn't going to keep track of it the way it does the rest of your programs - you'll have to manually upgrade it when necessary and manually remove it if you want it gone. Also, you'll have to know what packages it depends on (it sounds like you already use the program, so that's taken care of, but in general...).
How to Make Your Scripts Executable Everywhere in Linux
If you prefer a different editor like vi or vim, then you can replace the word nano in this command with the name of your favorite terminal text editor. Push the Page Down or cursor arrow down key to reach the bottom of the file and then add your path command. For instance, we added the line export PATH=$PATH:/home/user/Downloads at the bottom to make this a permanent location.
This post and this website contains affiliate links. See my disclosure about affiliate links.if(typeof ez_ad_units!='undefined')ez_ad_units.push([[300,250],'lostsaloon_com-box-1','ezslot_3',101,'0','0']);__ez_fad_position('div-gpt-ad-lostsaloon_com-box-1-0');report this adif(typeof ez_ad_units!='undefined')ez_ad_units.push([[728,90],'lostsaloon_com-box-2','ezslot_7',116,'0','0']);__ez_fad_position('div-gpt-ad-lostsaloon_com-box-2-0');how to make shell script executable from anywhere in linuxPosted on May 4, 2016July 20, 2019 bybarkeepif(typeof ez_ad_units!='undefined')ez_ad_units.push([[728,90],'lostsaloon_com-box-3','ezslot_6',102,'0','0']);__ez_fad_position('div-gpt-ad-lostsaloon_com-box-3-0');In Linux, shell scripts are the standard staple of everyday life. Most programs or software in Linux and Unix use some script file to start or run. It is roughly equivalent to executable files in Windows. You will also be able to create custom shell scripts to automate many of the everyday tasks as well.It is not uncommon to end up with several custom scripts that you will need to execute repeatedly. Most times it is a hassle to have type in the absolute path to the script or having to dig around as to where the file is. It makes it much easier to just type in the shell script name from any folder and execute it.A word of caution here, you will have to make sure that the shell script is written with the consideration that it can be executed from any directory. It should not make any assumption about the executing folder. If there are relative folders referred with in the commands with in the script, then you might be in for a surprise, but you already know that.The first step is to make the script executable and make sure that it has the appropriate permissions for the users executing it. You will need to set the executable bit on the file for the user groups.You also need to be aware of the path variable of the executing shell. In Linux environments, it is denoted by the PATH. You can view your current path by using the following command:bash$ echo $PATHRemember that if there are two scripts by the same name, then the first script found in the path will take precedence. The only way to execute the latter script will be to use the absolute path to the script.Shell Script in the PATHNow in order to make it executable from anywhere, you have two options:Copy the script into a folder that is already in the path: This option is most helpful if do not want to change the existing path variable. This is also a good way to keep your scripts all in one folder, which makes it easier to maintain on the long run.Add the path to the shell script to the path: You can add the path or the folder where the script is located into your path. This is quite useful if you cannot move script for some reason such as when the script is part of an installation of some third party software. But adding each and every folder where scripts exist can make the path pretty long and harder to maintain.You can follow some kind of standard process in order to keep it manageable and maintainable. I usually use two different predefined path or folders for scripts: /opt/bin/ and /bin/.The /opt/bin/ folder gets all the custom scripts that needs to be shared by different users or there are multiple user accounts that needs to execute it. This also hold the scripts that are part of a package or software installation.The /bin/ gets all the custom scripts that is local to me, and i am the only user executing it. These are usually custom scripts that perform a specific task such as searching or copying files etc etc.However, there is a small issue when you install packages or custom software. The startup scripts for these software exists in the location where the software is installed. If you installed them using a standard package manager specific to your distro, then appropriate symbolic links are created automatically in pre-existing path such as /usr/bin/. Otherwise, you will need to execute the script directly from the installation folder.
Python makes life so easy to write scripts for our desired outputs. Sometimes, we simply write a Python utility program that we want access from anywhere in the whole system. I will go through the series of steps you can follow to make your Python script executable in Linux (or Unix-like) system.
This will set your prefered editor to Vim, add your own lib/pythonsubdirectory for your Python libraries to your Python path, and add your ownbin directory as a place to put executable scripts. You need to logout andlog back in before your local bin directory will be in your search path.
When you create a Bash script and save it to a directory, you'll find that you can only execute the script while in that directory. By adding multiple links to it, you can also make your script executable everywhere.
Example. If I have /scripts/ in my path and in /scripts/ I have foo.sh I want to be able to be anywhere and type foo and have it execute foo.sh. When I type echo $PATH I see my scripts folder correctly included in my path. I've also made foo.sh executable because if I cd to the scripts directory and type foo.sh it runs correctly.
Right now our scripts work well, but they are not available system-wide as an executable file. Let's change that. For this final part we shall convert the site-check.sh script into an application that we can use from any location on the drive.
You can edit your script anywhere. You can also run it anywhere by simply typing its file path. If you want to run it just by typing its name, put the script in /usr/local/bin and make it executable. You can do this as shown above or do
True True. I think "most" of the stuff I have in there is actually symlinks. I have MATLAB and Mathematica installed to a non-standard location so that their files may be owned by a user with limited rights. I dropped symlinks to them in /usr/local/bin to make everything work easily. A few other scripts I have are linked to directories elsewhere I have tracked by git. I guess my main point was that either putting a script in there or linking something to there is a good way to do a few custom things in one nice "standard" place and still stay out of pacman's way.
You need to realize that your Python scripts have to be processed by anotherprogram called the Python interpreter. The interpreter reads your script,compiles it into bytecodes, and then executes the bytecodes to run yourprogram. So, how do you arrange for the interpreter to handle your Python?
A pre-built LAMMPS executable suitable for running on the latest UbuntuLinux versions, can be downloaded as a Debian package. This allows youto install LAMMPS with a single command, and stay (mostly) up-to-datewith the current stable version of LAMMPS by simply updating youroperating system.
This downloads an executable named lmp to your box and multiplepackages with supporting data, examples and libraries as well as anymissing dependencies. This executable can then be used in the usual wayto run input scripts:
If you've never heard of Cygwin, you're in for a treat. I've used it for years to homogenize my environments into one where I can write scripts once and deliver them everywhere for consistent automation solutions. It's a pain to write bash scripts that work on Linux, on Macs, and on commercial Unices, and then have to jump headlong into PowerShell and batch files to attempt to match the level of automation that I can achieve with some Bash scripting.
Open a browser on your Windows system and point it to the Cygwin web site. Select the Install Cygwin by running setup-x86_64.exe link to download the setup executable file. Run the executable file to begin the installation and click Next on the Cygwin Setup screen.
I suggest you peruse the different categories and make selections based on what you use on your Linux systems. I generally select OpenSSH, Bash, Bash-completion, Python, Tk/Tcl, and some other random applications. Once you've made your selections, click Next to continue.
Now that Cygwin is installed and the binaries are in your system path, you're probably wondering how you make this work. To invoke Bash, open a CMD window and type bash . You're now in a Bash shell that works exactly like your Linux one does. Try a few commands such as clear, ls, ls -la, pwd, and so on.
So, you see from these anomalies that Bash on Windows is not 100 percent equivalent to *nix Bash. Some scripts will translate directly, while others will have to be Window-ized. That is to say, customized to accommodate path differences, mount differences, and some file location differences. One really cool aspect of hybridizing your Windows environment is that you can also use Windows command line commands. You can pretty easily integrate them into your scripts. Remember to provide the full path to the executable in Cygwin format (/cygdrive/c/windows/system32/blah.exe). 2ff7e9595c
Comments