This question already has answers here:
what's the difference between ./script.sh and bash script.sh
(5 answers)
Difference between ./ and ~/
(6 answers)
Closed 3 years ago.
I downloaded IntelliJ IDEA for my linux system. It says to add the location of the bin folder of IntelliJ to the PATH environment variable in order to run IntelliJ from any folder.
So, I opened .bashrc and put in the address -
'export PATH=$PATH:/Documents/IntelliJ/bin' and then 'source ~/.bashrc'.
Then, to check I echoed by PATH and it showed the changes.
But, when I try to run './idea.sh' from some other directory it does not work. It says file not found. I have no idea what's hapenning?
Related
This question already has answers here:
How do I run a shell script without using "sh" or "bash" commands?
(13 answers)
Closed 1 year ago.
Issue
I want to run a bash file more easily, I've seen some applications where you only need to type word to execute the script.
Instead of typing ~/folder/file.sh in the terminal,
I only have to type a_word to run the file.
Is this possible with bash?
And also, this is on RPiOS's terminal, not sure if it differs.
Save your file to a location named in PATH. /usr/local/bin/a_word (no .sh) is a great example of such a location. Make sure it has executable permissions and starts with a shebang (like #!/usr/bin/env bash).
When you want to install something just for your own account, it's common practice to create a ~/bin directory and add it to your PATH (as by adding something like PATH=$PATH:$HOME/bin in ~/.bash_profile).
You have to define a so called alias.
Edit the file $HOME/.bashrc and add alias a_word = '$HOME/folder/file.sh', then logout and logon again.
This question already has answers here:
Add a bash script to path
(5 answers)
Closed 4 years ago.
I have my script in /home/testing/program. My script name is test.sh. I want to run my script from other directory. I changed the permissions of the file. In my script I have redirected the output to some(output-test.sh) file. I need to run all my script from other directory. If i run the script in the current directory it works fine. Please help me to do this. Thanks in advance.
In Unix systems, absolute paths start with / . So you can use absolute path to run a script. In your case all you have to do is run this command from the terminal
sh /home/testing/program/test.sh . It does not matter from which directory you run the command from until you use the absolute path of the script.
Also the file in which the output is written should be defined with absolute path in script file. For example, in your case
/home/centos/rr/email-body.txt
so that the file is recognized by the OS even when the script is executed from the other directory or from any directory whatsoever.
This question already has answers here:
Can I export a variable to the environment from a Bash script without sourcing it?
(13 answers)
Can a shell script set environment variables of the calling shell? [duplicate]
(20 answers)
Why doesn't a shell get variables exported by a script run in a subshell?
(2 answers)
Closed 5 years ago.
I have a file which contains the following commands,
export PATH=/gpfs/home/spandrekar/cse504/build_llvm/bin:$PATH
export LIBRARY_PATH=/gpfs/home/spandrekar/cse504/build_llvm/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/gpfs/home/spandrekar/cse504/build_llvm/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/gpfs/home/spandrekar/cse504/build_llvm/projects/openmp/runtime/src:$C_INCLUDE_PATH
export CC=clang
export CXX=clang++
I need to run these everytime I login to start my project. To make things easier, I am trying to run them using the command,
bash filename
However, this doesn't seem to work. When I type these commands on the commandline, it all works fine.
What am I missing here? How can I run the commands written in the file.
This question already has answers here:
How do you normalize a file path in Bash?
(24 answers)
Closed 6 years ago.
I've a shell script at
/home/abc/xyz/test.sh
I've a file at
/home/def/ghi/jkl/lmn/foo.txt
I'm running the scrip from /home as I've set my PATH variable to point to /home/abc/xyz/
I'm passing the relative path of foo.txt to my script like so test ./def/ghi/jkl/lmn/foo.txt
I want to capture the full path of foo.txt into a variable in my script, any pointers?
Tried https://stackoverflow.com/a/5265775 and https://stackoverflow.com/a/9107028/4468505 but in vain.
foobar=`readlink -f <passed in relative path to foo.txt>`
This question already has answers here:
How can I cd into a directory using a script?
(4 answers)
Closed 7 years ago.
My script
#!/bin/bash
for file in *.ats; do
mv $file /home/holmes/procmt
done
cd /home/holmes/procmt
All files are moved but I want to change my current directory to /home/holmes/procmt and nothing happens.WHY?
If i run script ./pch.sh,I stay in the same shell.
The shell running the script moved, but the shell you were typing in when you started the script stayed put. If you precede the name of your shell script with . (dot space) it will run in 'your' shell.