ksh to bash script conversion

ksh to bash script conversion

Post by Don Hard » Fri, 08 Jun 2001 06:37:25



Hello,

        I administer several computers used by students for course work.   I
have a little ksh script that locks the student accounts and replaces
their home directories with clean ones.  The ksh script is:

#! /bin/ksh
# locks user's accounts
#
# use this to get user names
##      cut -f1 -d: /etc/passwd grep string > user_list
##      edit user_list to included desired users
#
# run the script
##      lock user_list
#
for i in `cat ${1}`
do
# The first part locks the passwd of users in user_list
passwd -l $i
grep $i /etc/shadow
#
# This second part will remove the users' files
/bin/rm -rf ~$i
#
# This third part restores the default init files to the
# user accounts
mkdir -p ~$i
cp /etc/stdcshrc ~$i/.cshrc
cp /etc/stdlogin ~$i/.login
cp /etc/stdprofile ~$i/.profile
chown -R $i.user ~$i
ls -laFd ~$i
ls -laF ~$i
echo ""
echo ""
done

This works well for ksh but under bash none of the lines containing
~$i work.  I get error messages like "Cannot access ~username: No such
file or dirctory".  I've tried every form of quoting and escaping I
can think of, and I scanned the manual and HOWTOs but I can't get
"~$i" to work under bash.  What am I missing?

Thanks,

Don
--

Department of Chemistry     547 NSC
Georgia State University    ph: (404) 651-3580
Atlanta, Ga. 30302          fax:(404) 651-1416

 
 
 

ksh to bash script conversion

Post by N. Yeama » Fri, 08 Jun 2001 09:05:59


Upon the 06 of Jun in the hour of 15 MDT, the great Don Harden did decree:

...

Quote:> This works well for ksh but under bash none of the lines containing
> ~$i work.  I get error messages like "Cannot access ~username: No such
> file or dirctory".  I've tried every form of quoting and escaping I
> can think of, and I scanned the manual and HOWTOs but I can't get
> "~$i" to work under bash.  What am I missing?

Try the eval command. For example, the line that says 'ls -laF ~$i' should be:
eval ls -laF ~$i

This command forces bash to reevaluate the line after variable expansion is
done.

--


 
 
 

ksh to bash script conversion

Post by David Douthit » Fri, 08 Jun 2001 21:47:19



> This works well for ksh but under bash none of the lines containing
> ~$i work.  I get error messages like "Cannot access ~username: No such
> file or dirctory".  I've tried every form of quoting and escaping I
> can think of, and I scanned the manual and HOWTOs but I can't get
> "~$i" to work under bash.  What am I missing?

Try this (being funny.... and assuming RPM is available...):

# rm -f $(which bash)
# rpm -Uvh pdksh*
# /bin/ksh

In a more serious note, pdksh is a complete ksh and is available with
almost every Linux distribution; if you're going to do a lot of work
in ksh I'd recommend it.

 
 
 

ksh to bash script conversion

Post by Don Harde » Sat, 09 Jun 2001 01:34:37


Well, I went home last night and started to read (not just scan) Mendel
Cooper's Advanced Bash-Scripting HOWTO and found that in bash

        echo "ls -laF ~$i" |bash

will do the same as this in ksh

        ls -laF ~$i

BTW: eval did not work for me.

Thanks,
Don
--

Department of Chemistry        547 NSC
Georgia State University       ph: (404) 651-3580
Atlanta, Ga. 30302             fax: (404) 651-1416


> Upon the 06 of Jun in the hour of 15 MDT, the great Don Harden did decree:

> ....

>> This works well for ksh but under bash none of the lines containing
>> ~$i work.  I get error messages like "Cannot access ~username: No such
>> file or dirctory".  I've tried every form of quoting and escaping I
>> can think of, and I scanned the manual and HOWTOs but I can't get
>> "~$i" to work under bash.  What am I missing?

> Try the eval command. For example, the line that says 'ls -laF ~$i' should be:
> eval ls -laF ~$i

> This command forces bash to reevaluate the line after variable expansion is
> done.

 
 
 

ksh to bash script conversion

Post by N. Yeama » Sat, 09 Jun 2001 12:33:42



Quote:> Well, I went home last night and started to read (not just scan) Mendel
> Cooper's Advanced Bash-Scripting HOWTO and found that in bash

>    echo "ls -laF ~$i" |bash

> will do the same as this in ksh

>    ls -laF ~$i

> BTW: eval did not work for me.

eval didn't work?  That's strange.  It works on my version of bash--GNU bash
ver 2.05.0(1)-release (i386-slackware-linux-gnu)  Do you have an older
version maybe?

Anyway, I'm glad you've got it working.  Sorry my suggestion didn't help.

--