Sponsored Content
Full Discussion: Problem understanding Paths
Top Forums UNIX for Dummies Questions & Answers Problem understanding Paths Post 302646923 by Chasman78 on Saturday 26th of May 2012 01:43:53 PM
Old 05-26-2012
Problem understanding Paths

If I don't explain my issue well enough, I apologize ahead of time, extreme newbie here to scripting.

I'm currently learning scripting from books and have moved on to the text Wicked Cool Shell Scripts by Dave Taylor, but there are still basic concepts that I'm having trouble understanding.

The code I was working with is meant to verify whether a particular program is valid or can be found in the path directory list. It's the latter process that I don't understand will explain further. The code I was working with is as follows (p. 11 of Wicked Cool Shell Scripts)

Code:
 
#!/bin/sh

in_path()
{
cmd=$1   path=$2   retval=1
oldIFS=$IFS   IFS-":"

for directory in $path
do
   if [ -x $direcotry/$cmd ] ; then
   retval =0
   fi
done
IFS=$oldIFS
return $retval
}

checkForCmdInPath()
{
   var=$1
   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 command" >&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


Now when I enter 'inpath echo' at the command line (as per the instructions) I get this error message

-bash: inpath: command not found

I'm pretty certain I entered the code correctly, so I'm assuming the problem has to do with my not understanding the concept of paths, and so far no text has explained it in a way that I've understood so far.

Could someone please help me understand this because I'm currently stuck.
 

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
xotclsh(1)							XOTcl Applications							xotclsh(1)

__________________________________________________________________________________________________________________________________________________

NAME
xotclsh - Tcl Shell containing object-oriented scripting language XOTcl SYNOPSIS
xotclsh ?filename arg arg ...? _________________________________________________________________ DESCRIPTION
xotclsh is a shell-like application that reads XOTcl commands from its standard input or from a file and evaluates them. Similarly as the relation between tclsh and wish, xowish provides all functionality of xotclsh and provides as well predefined support for TK widgets. XOTcl (XOTcl, pronounced exotickle) is an object-oriented scripting language based on MIT's OTcl. It is intended as a value added replace- ment of OTcl. Scripting languages, such as Tcl, are designed for glueing components together, provide features such as dynamic extensibility and dynamic typing with automatic conversion, that make them well suited for rapid application development. The object system of XOTcl enables a user to to define objects, classes, and meta-classes. Classes are special objects with the purpose of managing other objects. ``Managing'' means that a class controls the creation and destruction of its instances and that it contains a repository of methods accessible for the instances. Every object may be enhanced with object-specific methods. XOTcl supports single and multiple inheritance. All object-class and class-class relationships in XOTcl are introspectable and can be dynamically changed at arbi- trary times. Ambiguities in name resolution of methods are avoided through method chaining through "next", which does not require explicit method naming. XOTcl combines the ideas of scripting and object-orientation in a way that preserves the benefits of both of them. It is equipped with sev- eral new language constructs that help building and managing complex systems. We added the following support: Dynamic Object Aggregations, to provide dynamic aggregations through nested namespaces (objects). Nested Classes, to reduce the interference of independently developed program structures. Assertions, to reduce the interface and the reliability problems caused by dynamic typing and, therefore, to ease the combination of many components. Meta-data, to enhance self-documentation of objects and classes. Per-object mixins, as a means to give an object dynamically access to the methods of one or several supplemental classes. Per-class mixins, as a means to give all instances of an class dynamically access to the methods of one or several supplemental classes. Filters as a means of abstractions over method invocations to implement large program structures, like design patterns. XOTcl provides a value-added replacement of Tcl package loading providing integration with object-oriented constructs and tracking/tracing of component loading. VARIABLES
xotclsh sets all variables that tclsh sets, and additionally the following variables: ::xotcl::version XOTcl version number. ::xotcl::confdir Directory for XOTcl configuration. ::xotcl::logdir Directory where logfiles are placed. KEYWORDS
argument, interpreter, prompt, script file, shell XOTcl xotclsh(1)
All times are GMT -4. The time now is 12:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy