12-27-2018
PATH is something that tells the computer where to look for programs, and in what order to search for the programs.
By programs, I am referring to many of the commands you use in unix - cp, rm, mv, cat - are actually programs.
So, if you type 'cat myfile', unix would look in /usr/bin folder first to find the program cat.exe; then it will do what cat is programmed for, display the contents of the parameter you typed, myfile
Defining data_dir is a common programming step. This avoids the need to specify it everywhere in your script, and (MOST IMPORTANTLY) allows you to adjust the location just once rather than throughout your script.
thus, in your script you could have the following commands (if the archiv_dir was also defined):
cat $data_dir"/workfile.txt"
mv $data_dir"/workfile.txt" $archv_dir"/workfile.arc"
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I am trying to create an alias for a frequently used directory path by using
alias xyz="/proj/dir_name"
and then trying to reach a sub-directoy by using
cd xyz/abc
but I get an error saying " No such file or directory "
plz tell me wats wrong with this ... (3 Replies)
Discussion started by: jasjot31
3 Replies
2. UNIX for Dummies Questions & Answers
I cannot seem to get the following script to work. I cannot seem to set the variable. What am I missing?
bin/bash
set -x
echo "2" > /tmp/number
STATUS='grep -c 2 /temp/number'
if ; then
echo "Number 2 is found once"
else
echo "Number 2 is found more or less than one time"
fi (3 Replies)
Discussion started by: rexmabry
3 Replies
3. Shell Programming and Scripting
Hi,
I am having a variable
Like
line="/dir1/dir2/gr3/file.ksh"
I need to get the /dir1/dir2/gr3 alone. the no of directories may differ at each time.
Please advice. thanks in advance. (3 Replies)
Discussion started by: vanathi
3 Replies
4. Shell Programming and Scripting
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Discussion started by: alrinno
2 Replies
5. Shell Programming and Scripting
Hi
I need a script which will remove a path from PATH environment variable. For example
$echo PATH
/usr/local/bin:/usr/bin:test/rmve:/usr/games
$echo rmv
test/rmve
Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Discussion started by: madhu84
9 Replies
6. Shell Programming and Scripting
Hi,
Could anyone help me in writing a single line code by either using (sed, awk, perl or whatever) to extract a specific path from the PATH environment variable?
for eg: suppose the PATH is being set as follows
PATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/bin/java:/usr/bin/perl3.4
... (2 Replies)
Discussion started by: royalibrahim
2 Replies
7. Shell Programming and Scripting
Hello Folks,
I want to append a path in user's PATH variable which should be available in current session.
Background
Numerous persons will run a utility.
Aim is to add the absolute path of the utility the first time it runs so that next runs have the PATH in env & users can directly run... (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies
8. Shell Programming and Scripting
Hi I'm trying to select text between two lines, I'm using sed to to this, but I need to pass variables to it. For example
start="BEGIN /home/mavkoup/data"
end="END"
sed -n -e '/${start}/,/${end}/g' doesn't work. I've tried double quotes as well. I think there's a problem with the / in the... (4 Replies)
Discussion started by: mavkoup
4 Replies
9. Shell Programming and Scripting
I am submitting a concurrent program (of HOST tyme) from Oracle apps screen,
The MAIN shell program submits another program, (child) which is also a Shell program. The child writes data to log file. Now the main program, read the log and do some calculations and sends the data to user through... (1 Reply)
Discussion started by: Pradeep Garine
1 Replies
10. Shell Programming and Scripting
Need a way to read a file in who every line is a path to a directory and make shortcut to that directory on a specific place.
Example:
line in the document
/media/gogo/6651-FEAB/Desktop/
/media/gogo/6651-FEAB/Desktop/alex/
/media/gogo/6651-FEAB/linux/ ... (3 Replies)
Discussion started by: gogok_bg
3 Replies
WHICH(1) General Commands Manual WHICH(1)
NAME
which - shows the full path of (shell) commands.
SYNOPSIS
which [options] [--] programname [...]
DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been exe-
cuted when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories
listed in the environment variable PATH using the same algorithm as bash(1).
This man page is generated from the file which.texinfo.
OPTIONS
--all, -a
Print all matching executables in PATH, not just the first.
--read-alias, -i
Read aliases from stdin, reporting matching ones on stdout. This is useful in combination with using an alias for which itself. For
example
alias which='alias | which -i'.
--skip-alias
Ignore option `--read-alias', if any. This is useful to explicity search for normal binaries, while using the `--read-alias' option in
an alias or function for which.
--read-functions
Read shell function definitions from stdin, reporting matching ones on stdout. This is useful in combination with using a shell func-
tion for which itself. For example:
which() { declare -f | which --read-functions $@ }
export -f which
--skip-functions
Ignore option `--read-functions', if any. This is useful to explicity search for normal binaries, while using the `--read-functions'
option in an alias or function for which.
--skip-dot
Skip directories in PATH that start with a dot.
--skip-tilde
Skip directories in PATH that start with a tilde and executables which reside in the HOME directory.
--show-dot
If a directory in PATH starts with a dot and a matching executable was found for that path, then print "./programname" rather than the
full path.
--show-tilde
Output a tilde when a directory matches the HOME directory. This option is ignored when which is invoked as root.
--tty-only
Stop processing options on the right if not on tty.
--version,-v,-V
Print version information on standard output then exit successfully.
--help
Print usage information on standard output then exit successfully.
RETURN VALUE
Which returns the number of failed arguments, or -1 when no `programname' was given.
EXAMPLE
The recommended way to use this utility is by adding an alias (C shell) or shell function (Bourne shell) for which like the following:
[ba]sh:
which ()
{
(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
}
export -f which
[t]csh:
alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
This will print the readable ~/ and ./ when starting which from your prompt, while still printing the full path when used from a script:
> which q2
~/bin/q2
> echo `which q2`
/home/carlo/bin/q2
BUGS
The HOME directory is determined by looking for the HOME environment variable, which aborts when this variable doesn't exist. Which will
consider two equivalent directories to be different when one of them contains a path with a symbolic link.
AUTHOR
Carlo Wood <carlo@gnu.org>
SEE ALSO
bash(1)
WHICH(1)