- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Modify a script to work on bash shell rather than ...
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
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
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
11-13-2012 01:20 AM
11-13-2012 01:20 AM
Hi
what needs to be taken into account when writing for bash? I have a small script that does not work on bash, but is does if I type first ksh on comand prompt
#!/bin/ksh for dir in directory1/subdirectory /directory2/subdirectory /directory3/subdirectory do echo "$dir $( du $dir |wc -l)" done > ./message1 mailx -s "number of files" fretagi@mcel.co.mz < ./message1
Solved! Go to Solution.
- Tags:
- bash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 02:00 AM
11-13-2012 02:00 AM
Re: Modify a script to work on bash shell rather than ksh
Why would you want to port from a real shell to bash?
If this is because of Linux, you are in the wrong board.
What happens if you just use bash on that fragment?
>echo "$dir $(du $dir | wc -l)"
If you want the number of files in $dir, you shouldn't be using du(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 02:08 AM
11-13-2012 02:08 AM
Re: Modify a script to work on bash shell rather than ksh
Hi
I had originaly had:
a=`/directory/subdirectory/ | wc -l` echo "/directory/subdirectory :$a" b=`/another_dir/subdir/ | wc -l` echo "/another_dir/subdir :$b"
I wanted to
while
But a friend told me to use
du
So, can you advise?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 02:32 AM
11-13-2012 02:32 AM
Re: Modify a script to work on bash shell rather than ksh
>I had originally had:
Your archaic `` needs a command:
dir=/directory/subdirectory
echo "$dir: $(ls $dir | wc -l)"
dir=/another_dir/subdir
echo "$dir: $(ls $dir | wc -l)"
>But a friend told me to use du:
A ls(1) or find would work better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 08:51 AM
11-13-2012 08:51 AM
Re: Modify a script to work on bash shell rather than ksh
First
#!/usr/bin/ksh and not #!/bin/ksh
no need for echo "$dir $(....
Then
#!/usr/bin/ksh for dir in directory1/subdirectory /directory2/subdirectory /directory3/subdirectory do
echo "$dir \c"
find "$dir" | wc -l
done > ./message1 mailx -s "number of files" fretagi@mcel.co.mz < ./message1
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 03:08 PM
11-13-2012 03:08 PM
SolutionPerhaps I'm confused. Did you want to port the script to bash or run it under a bash shell?
I found the script works without changes under bash. And the #! line should enable it to work under bash.
It looks like the du - wc pipeline counts directories not files so you could do this:
echo "$dir $(find $dir -type d | wc -l)"
>#!/usr/bin/ksh and not #!/bin/ksh
If the permanent transition links are there, it should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 11:06 PM
11-13-2012 11:06 PM
Re: Modify a script to work on bash shell rather than ksh
Hi
I want to run under the bash shell, and for some strange reason its printing only single digits, but there 3 digits number there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 11:42 PM
11-13-2012 11:42 PM
Re: Modify a script to work on bash shell rather than ksh
>it's printing only single digits, but there 3 digits number there.
Can you provide the output of the script?
And what do you want the script to do with each directory?
Count the number of files or only subdirectories?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 11:45 PM
11-13-2012 11:45 PM
Re: Modify a script to work on bash shell rather than ksh
the output is:
/nikira/NIKIRAROOT/RangerData/DiamondTemp/Mcel_Ericsson_CDR_Temp 1
/nikira/NIKIRAROOT/RangerData/DiamondTemp/Mcel_Ericsson_SGSN_Temp 2
/nikira/NIKIRAROOT/RangerData/DiamondTemp/Mcel_Ericsson_GGSNCDR_Temp 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2012 11:48 PM
11-13-2012 11:48 PM
Re: Modify a script to work on bash shell rather than ksh
>The script is to only count the number of files in the subdirectories:
And are you using du(1), ls(1) or find?