Sponsored Content
Full Discussion: Problem understanding Paths
Top Forums UNIX for Dummies Questions & Answers Problem understanding Paths Post 302646945 by Chasman78 on Saturday 26th of May 2012 02:40:42 PM
Old 05-26-2012
I forgot to mention that I get this error message after entering ./inpath echo at the command line:

./inpath: line 48: checkforCmdInPath: command not found

---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ----------

Sorry, I meant that I had already done those two things before even writing this post.

---------- Post updated at 02:40 PM ---------- Previous update was at 02:38 PM ----------

Here's my actual code (I'm embarrassed I didn't think to just cut and paste like normal):

Code:
#!/bin/sh
# inpath - Verifies that a specified program is either valid as is, 
# or that it can be found in the PATH directory list.

in_path()
{
	# Given a command and the PATH, try to find the command.  Returns
	# 0 if found and executable, 1 if not.  Note that this temporarily modifies 
	# the IFS (input field separator) but restores it upon completion.

	cmd=$1		path=$2		retval=1
	oldIFS=$IFS	IFS=":"

	for directory in $path
	do
		if [ -x $directory/$cmd ] ; then
		retval=0   # if we're here, we found $cmd in $directory
		fi
	done
	IFS=$oldIFS
	return $retval
}

checkForCmdInPath()
{
	var=$1
	# The variable slicing notation in the following conditional
	# needs some explanation: ${var#expr} returns everything after
	# the math for 'expr' in the variable value (if any), and 
	# ${var%espr} returns everything that doesn't match (in this
	# case, just the very first character.  You can also do this in
	# Bash with ${var:0:1}, and you could use cut too: cut -c1.

	if [ "$var" != "" ] ; then
		if [ "${var%${var#?}}" = "/" ] ; then
			if [ ! -x $var ] ; then
				return 1
			fi
		elif ! in_path $var $PATH ; then
			return 2
		fi
	fi
}
	if [ $# -ne 1 ] ; then
		echo "Usage: $0 comand" >&2 ; exit 1
	fi

	checkforCmdInPath "$1"
	case $? in
		0) echo "$1 found in PATH"	;;
		1) echo "$1 not found or not executable"	;;
		2) echo "$1 not found in PATH"	;;
	esac

	exit 0

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

paths

Hi there! People, i'm a new unix user, and i'm having some problems... I'm updating some scripts (korn shell) in different servers. I use telnet to access these servers and emacs to write the scripts. One of them is an HP, and there´s no problem. But the other one is an AIX, and when i call... (1 Reply)
Discussion started by: caiohn
1 Replies

2. Filesystems, Disks and Memory

having problem in understanding namei module

can anyone give me some idea on unix filesystem namei's algorithsm (2 Replies)
Discussion started by: kangc
2 Replies

3. Shell Programming and Scripting

egrep understanding problem

Hi, Can anyone please let me know the meaning of this line,i am not able to understand the egrep part(egrep '^{1,2}).This will search for this combination in beginning but what does the values in {}signifies here. /bin/echo $WhenToRun | egrep '^{1,2}:$' >/dev/null (1 Reply)
Discussion started by: namishtiwari
1 Replies

4. AIX

Problem in understanding the output of errpt -d H -T PERM -s `date +"%m%d%H00%y"`

Its very critical and 'm in need to schedule this on my crontab so that the output can be monitored by a tool I have written the command below to redirect the error which has the output redirected to the file gincle_lol.log. Code: echo "---" >>/gingle/gincle_lol.log date... (0 Replies)
Discussion started by: Sounddappan
0 Replies

5. Shell Programming and Scripting

problem in understanding the output of errpt -d H -T PERM -s `date +"%m%d%H00%y"`

Its very critical and 'm in need to schedule this on my crontab so that the output can be monitored by a tool I have written the command below to redirect the error which has the output redirected to the file gincle_lol.log. echo "---" >>/gingle/gincle_lol.log date... (1 Reply)
Discussion started by: Sounddappan
1 Replies

6. Shell Programming and Scripting

Problem with the shell script for understanding

Can Anybody please tell me the meaning of the script: #!/bin/sh str=$@ echo $str | sed 's/.*\\//' exit 0 (6 Replies)
Discussion started by: nixhead
6 Replies

7. Shell Programming and Scripting

Problem in understanding export uses

i am beginner in shell scripting. not able to understand what below line will do. PS1=${HOST:=´uname -n´}"$ " ; export PS1 HOST below is the script #!/bin/hash PS1=${HOST:=´uname -n´}"$ " ; export PS1 HOST ; echo $PS1 and i getting the below output ´uname -n´$ (25 Replies)
Discussion started by: scriptor
25 Replies

8. Shell Programming and Scripting

Problem on understanding the regexp command

Hi all, I'm not clear of this regexp command: regexp {(\S+)\/+$} $String match GetString From my observation and testing, if $String is abc/def/gh $GetString will be abc/def I don't understand how the /gh in $String got eliminated. Please help. Thanks (2 Replies)
Discussion started by: mar85
2 Replies

9. Shell Programming and Scripting

Problem in understanding debugging

Hi i was going through the script debugging technique. below example was given in the book. 1 #!/bin/sh 2 3 Failed() { 4 if ; then 5 echo "Failed. Exiting." ; exit 1 ; 6 fi 7 echo "Done." 8 } 9 10 echo "Deleting old backups,... (11 Replies)
Discussion started by: scriptor
11 Replies

10. Shell Programming and Scripting

Problem with (Understanding) function

I have this code #!/bin/bash LZ () { RETVAL="\n$(date +%Y-%m-%d_%H-%M-%S) --- " return RETVAL } echo -e $LZ"Test" sleep 3 echo -e $LZ"Test" which I want to use to make logentrys on my NAS. I expect of this code that there would be output like 2017-03-07_11-00-00 --- Test (4 Replies)
Discussion started by: matrois
4 Replies
openipmish(1)						 Shell interface to an IPMI system					     openipmish(1)

NAME
openipmish - Shell interface to an IPMI system SYNOPSIS
openipmish [option] DESCRIPTION
The openipmish is a command interpreter that gives the full power of the OpenIPMI library to a user-level command language. It is designed so it can easily be driven with a scripting language like TCL, it has well-formed output. openipmish starts up with no connections or anything of that nature. You must enter commands to make connections to domains. OPTIONS
--dmsg Turn on message debugging, this will dump all messages to debug log output. --drawmsg Turn on raw message debugging, this will dump all low-level messages to debug log output. This differes from normal message debug- ging in that all protocol messages are also dumped, not just IPMI messages. --dmem Turn on memory debugging, this will cause memory allocation and deallocations to be checked. When the program terminates, it will dump all memory that was not properly freed (leaked). --dlock Turn on lock debugging, this will check lock operations to make sure that locks are help in all the proper places and make sure that locks are properly nested. --snmp Enable the SNMP trap handler. openipmish must be compiled with SNMP code enabled for this option to be available. --help Help output COMMANDS
openipmish follows the standard command syntax defined in ipmi_cmdlang(7). See that for the details on most commands. The IPMI manual that comes with OpenIPMI will also be quite handy. openipmish defines some commands that are not in the standard command language. These are: read Read and execute commands from the given file. exit Quit redisp_cmd on|off Normally, openipmish redisplays the command line when an event comes in. This is nice for interactive use, but bad for scripting. This lets you turn that function on and off. SEE ALSO
ipmi_cmdlang(7), ipmi_ui(1) KNOWN PROBLEMS
None AUTHOR
Corey Minyard <cminyard@mvista.org> OpenIPMI 05/13/03 openipmish(1)
All times are GMT -4. The time now is 06:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy