Sponsored Content
Full Discussion: korn shell homework
Top Forums Shell Programming and Scripting korn shell homework Post 21239 by Loppdawg69 on Tuesday 14th of May 2002 02:16:12 AM
Old 05-14-2002
korn shell homework

here are the questions for ya...im stumped

1)the command "dirname path" treats path as a pathnameand writes to the standard output the path prefix, that is everything up to but not including the last component. thus "dirname a/b/c/d" write a/b/c to standard output. If path is simple filename (has no / characters), then dirname writes a . to standard output. Implement "dirname" as a Korn Shell function. Make sure that it behaves sensibly when given values of path such as /.

2)implement the basename utility, which writes the last component of its pathname argument to standard output, as a Korn Shell function. For example

basename a/b/c/d

writes d to standard output.

3) The UNIX basename utility has an optional third argument. If you type suffix of path that is identical to suffix. For example

$ basename src/shellfiles/prog.sh .sh
prog
$ basename src/shellfiles/prog.sh .c
prog.sh

add this feature to the function you wrote for problem 2.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell

Hi I am new to shell programming. I need help to write a script to monitor a process on Sun OS. If the process fails then call a oracle procedure. i check the process if running by typing ps -ef | grep ESP | grep -v grep root 29002 1 0 Mar 18 ? 7:20... (4 Replies)
Discussion started by: gpanesar
4 Replies

2. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

3. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

4. UNIX for Dummies Questions & Answers

bourne shell or korn shell?

Hi, I have a script that uses "nohup" command to execute a korn shell script. Which one is the correct shell to use bourne shell or korn shell to execute a korn shell? and why? Thanks in advanced. (2 Replies)
Discussion started by: XZOR
2 Replies

5. UNIX for Dummies Questions & Answers

what are some different commands in c shell and korn shell??

I am doing this simple script using c shell and korn shell. The commands I use are fgrep , ls, and also some redirecting. Is there any difference in using both of these commands in c shell and korn shell? Thanks and sorry for the stupid question. (1 Reply)
Discussion started by: EquinoX
1 Replies

6. Shell Programming and Scripting

how can i call one korn shell from a shell

Hi guys, please help me I have a ksh script (second picture down), in that script I define the function DATECALC. Now I want to use this function KSH in a program shell. How can I call this ksh from my shell program? My shell program is... in the first two lines I tried to call... (1 Reply)
Discussion started by: acevallo
1 Replies

7. Shell Programming and Scripting

korn shell

I am using korn shell but I want to have my prompt to represnent that of my C shell because I like it better. Is there anyway to do this? (1 Reply)
Discussion started by: vthokiefan
1 Replies

8. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

9. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

10. Shell Programming and Scripting

New to korn shell

I am new to korn shell and slowly learning. Is there a way to have a parent script prompt for input and then execute a child script and return the output then move forward and ask for more input and then execute the next child script? I think the answer is no but thought i would ask. (2 Replies)
Discussion started by: cptkirkh
2 Replies
basename(1)						      General Commands Manual						       basename(1)

NAME
basename, dirname - Returns the base file name or directory portion of a path name SYNOPSIS
basename string [suffix] dirname string STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: basename: XCU5.0 dirname: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
A string to be evaluated. This string may be empty. A file name suffix to be deleted if found. This operand applies to the basename com- mand only, and is optional. DESCRIPTION
The basename command reads the string specified on the command line, deletes the portion from the beginning to the last / (slash), and writes the base file name to standard output. If suffix is specified on the command line and suffix appears in string, the string is returned with the suffix removed. The dirname command reads the string specified on the command line, deletes from the last / (slash) to the end of the line, and writes the remaining path name to standard output. [Tru64 UNIX] The basename and dirname commands are generally used inside command substitutions within a shell procedure to specify an out- put file name that is some variation of a specified input file name. For more information, see the csh(1), ksh(1), and sh(1b) or sh(1p) reference pages. The following table demonstrates the processing applied to characters with particular meanings by the basename and dirname commands. ------------------------------ basename dirname string Result Result ------------------------------ / / / // / / /a/b b /a //a//b// b //a <null> err msg err msg a a . "" . /a a / /a/b b /a a/b b a ------------------------------ NOTES
It is not an error if suffix is not a part of string. EXAMPLES
To display the base file name of a shell variable, enter: basename $WORKFILE This displays the base file name of the value assigned to the WORKFILE shell variable. If WORKFILE is set to /u/gabe/program.c, then program.c is displayed. To construct, in a shell script, a file name that is the same as another file name, except for its suffix, enter the following command, using grave accents: OFILE=`basename $1 .c`.o This assigns to OFILE the value of the first positional parameter ($1), but with its suffix changed to $1 is /u/jim/program.c, then OFILE becomes program.o. Because program.o is only a base file name, it identifies a file in the current directory. The grave accents perform command substitution. To construct the name of a file located in the same directory as another, enter the following command, using grave accents: AOUTFILE=`dirname $TEXTFILE`/a.out This sets the AOUTFILE shell variable to the name of an a.out file that is in the same directory as TEXTFILE. If TEXTFILE is /u/fran/prog.c, then the value of dirname $TEXTFILE is /u/fran and AOUTFILE becomes /u/fran/a.out. ENVIRONMENT VARIABLES
The following environment variables affect the execution of basename and dirname: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the inter- nationalization variables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non- empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: csh(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p) Standards: standards(5) basename(1)
All times are GMT -4. The time now is 06:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy