- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- for loop and cd ~
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 09:46 PM
05-26-2004 09:46 PM
I am trying to write a script to cd to a list of users home directories using a for in i and cd ~$i but it keeps complaining....
script is
for i in `cat userlist`
do
echo $i
cd ~$i
done
It echoes the $i but gives me an error then for the cd
barbara (successful echo $i)
ksh[4]: ~barbara: not found (failed cd ~$i)
I am sure it is something simple.....I have tried quotes adn brackets all over the place but nothing seems to work.....
Anyone got any ideas??
Cheers Barbara
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 09:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 09:57 PM
05-26-2004 09:57 PM
Re: for loop and cd ~
Please use sh-posix, that will solve your problem. I mean you need to add "#!/usr/bin/sh" in the first line of your program and then your script should work fine.
So your script should look like following:
----------------------
#!/usr/bin/sh
for i in `cat userlist`
do
echo $i
cd ~$i
done
-----------------------
This should solve your problem.
Cheers,
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 11:02 PM
05-26-2004 11:02 PM
Re: for loop and cd ~
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 11:02 PM
05-26-2004 11:02 PM
Re: for loop and cd ~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 11:16 PM
05-26-2004 11:16 PM
Re: for loop and cd ~
You can not run cd ~$i until you are using sha-bang(#!/usr/bin/sh) or eval command.
The first one will tell that this is a shell script(not comment).
Rgds
Tapas