The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[kornshell] Getting the next weekday date rs_f01 UNIX for Dummies Questions & Answers 1 08-10-2005 12:34 AM
Need Help with KornShell script ckrieger1 Shell Programming and Scripting 1 02-13-2004 10:34 AM
Kornshell convdate nezster High Level Programming 10 12-30-2003 12:17 PM
mailx in kornshell script passing return code to CA-Unicenter Connie UNIX for Advanced & Expert Users 1 04-23-2002 09:45 AM
Kornshell 93 Ask Me UNIX for Dummies Questions & Answers 1 07-12-2001 05:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-12-2004
ckrieger1 ckrieger1 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 2
help with Kornshell function

I am trying to write a Kornshell function that takes a string parameter which represents a filename or directory name. The function checks to see if there are any spaces in the filename or directory name and then replaces the spaces with an underscore. The returned value is a filename or directory name without any spaces. Thanks for any suggestions you may have.
  #2 (permalink)  
Old 04-12-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805

Code:
#! /bin/ksh
result=""              
differ=0
function repspace
{    
  differ=0           
  echo $1 | grep -q " "
  if [ $? -eq 0 ] ; then
     result=`echo $1 | sed 's/ /_/g'`  
     differ=1
  fi

}       

for file in *.shl
do
    repspace $file
    if [ differ -eq 1 ] ; then
        mv $file $result
    fi
done

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0