Working with FOR in ksh 88 | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Working with FOR in ksh 88

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-15-2013
smile689 smile689 is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 28 January 2014, 5:59 AM EST
Posts: 59
Thanks: 38
Thanked 0 Times in 0 Posts
Working with FOR in ksh 88

Hi,
I tried the following but giving me all the files in the directory ,
Where i need the files which are assigned to variable like below

Code:
#!/bin/ksh

Src_Dir="/home/etc"
file_nm ="ab.temp"
  for File in `ls $Src_Dir/$file_nm*`
    do
    
    File=`basename $File`
    echo $File
  done

please help me
Sponsored Links
    #2  
Old 10-15-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 26 July 2014, 3:41 PM EDT
Location: Vienna, Austria
Posts: 789
Thanks: 18
Thanked 167 Times in 149 Posts

Code:
...
    for File in $Src_Dir/$File_nm*
...

The Following User Says Thank You to hergp For This Useful Post:
smile689 (11-04-2013)
Sponsored Links
    #3  
Old 10-15-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 1 August 2014, 1:41 AM EDT
Location: San Jose, CA, USA
Posts: 4,213
Thanks: 165
Thanked 1,435 Times in 1,216 Posts
Quote:
Originally Posted by smile689 View Post
Hi,
I tried the following but giving me all the files in the directory ,
Where i need the files which are assigned to variable like below

Code:
#!/bin/ksh

Src_Dir="/home/etc"
file_nm ="ab.temp"
  for File in `ls $Src_Dir/$file_nm*`
    do
    
    File=`basename $File`
    echo $File
  done

please help me
The suggestion hergp made shows you how to use the for loop. A simpler way to perform what this script does is:

Code:
#!/bin/ksh
Src_Dir="/home/etc"
file_nm ="ab.temp"
cd "$Src_Dir"
printf "%s\n" $file_nm*

If there is more to do in the script that needs to be run from the directory in which the script started, add the following line to the end of the script:

Code:
cd -

before the remainder of your code.
The Following User Says Thank You to Don Cragun For This Useful Post:
smile689 (11-04-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh script not working jgt157 Shell Programming and Scripting 3 06-10-2013 08:58 PM
If statement is not working in KSH saggy9583 Shell Programming and Scripting 31 02-10-2011 10:39 AM
du not working for user using ksh robertngo AIX 5 08-05-2008 07:33 AM
Substitution not working in ksh arsheshadri AIX 2 04-12-2007 07:30 AM
ls not working as expected within ksh GNMIKE Shell Programming and Scripting 10 07-07-2005 07:53 AM



All times are GMT -4. The time now is 01:45 AM.