- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- LS Script
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
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
01-14-2004 10:28 PM
01-14-2004 10:28 PM
Kindly help to write a script to get the file list with sequence no. If total no. of files to be selected is more than 10 then it should ask me two option whether to go next or want to select the file which was displayed using sequence no.
ls *A* --> total no of such files are 25
files should be displayed as below,
1. A1
2. A2
....
10. A10
Hit Enter for Next Page OR Select file no to display File
So if i press enter it should display next page and if i press file no it should display that filename.
I hope you understand my requirement.
Points will be given to all answers.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 10:41 PM
01-14-2004 10:41 PM
Re: LS Script
export COUNT=0
for i in `ls`
do
let COUNT="COUNT++1"
echo "$COUNT $i"
done
HTH,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 10:53 PM
01-14-2004 10:53 PM
Re: LS Script
But you need to have it interactively. So it will become something like this:
cnt=1
ls *A* | while read file
do
filelist[$cnt]=$file
(( cnt = $cnt + 2 ))
done
page=1
while [ true ]
do
(( idx = ( $page - 1 )* 10 + 1 ))
while [ $idx -le (( $page * 10)) -a $idx -lt $cnt ]
do
printf "%4d %s\n",$idx,$filelist[$idx]
done
echo "Hit Enter for Next Page OR Select file no to display"
read answer
case "$answer"
"") (( page = $page + 1 ))
break
*) if [ -n "$filelist[$answer]" ]
then
cat $filelist[$answer]
else
echo "File does not exist"
fi
echo "Press return to continue"
read dummy
break
esac
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 11:08 PM
01-14-2004 11:08 PM
Re: LS Script
clear; ll |nl |more -10
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 11:10 PM
01-14-2004 11:10 PM
Re: LS Script
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2004 03:21 AM
01-15-2004 03:21 AM
Re: LS Script
Elmar after executing your code i'm getting error at line 13.
Can you tell what could it be?
Thanks ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2004 05:25 PM
01-15-2004 05:25 PM
Solution#! /bin/ksh
set -A filelist 1024
cnt=0
ls *A* | while read file
do
(( cnt = $cnt + 1 ))
filelist[$cnt]=$file
done
echo $cnt
page=0
(( maxidx = $page * 10 ))
while [ $maxidx -lt $cnt ]
do
(( page = $page + 1 ))
(( maxidx = $maxidx + 10 ))
(( idx = $maxidx - 9 ))
[ $maxidx -gt $cnt ] && maxidx=$cnt
while [ $idx -le $maxidx ]
do
printf "%4d %s\n" $idx ${filelist[$idx]}
(( idx = $idx + 1 ))
done
echo "Hit Enter for Next Page OR Select file no to display"
read answer
case "$answer" in
"")
;;
*) if [ -n "${filelist[$answer]}" ]
then
cat ${filelist[$answer]}
else
echo "File does not exist"
fi
echo "Press return to continue"
read dummy
(( page = $page - 1 ))
(( maxidx = $page * 10 ))
;;
esac
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2004 05:51 PM
01-15-2004 05:51 PM
Re: LS Script
I have 21 files in my dir. A1 to A21.
I'hv tested your script, which is failing to show the filename for which i have enter the sequence no.
./p1
21
1 A1
2 A10
3 A11
4 A12
5 A13
6 A14
7 A15
8 A16
9 A17
10 A18
Hit Enter for Next Page OR Select file no to display
11 A19
12 A2
13 A20
14 A21
15 A3
16 A4
17 A5
18 A6
19 A7
20 A8
Hit Enter for Next Page OR Select file no to display
12 <=== Input from me.
So output should be "A2"
But it is continuing the loop again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2004 06:15 PM
01-15-2004 06:15 PM
Re: LS Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2004 11:48 PM
01-15-2004 11:48 PM
Re: LS Script
This one simply uses the "select" function of sh. The only problem is that "Enter" redisplays current page, while any other input goes to next page (except if you select a number of course) :
#!/usr/bin/sh
LIST=$(ls -1 | tr '\012' ' ')
NB=10
PS3="Hit N for Next Page OR Select file no to display "
while [ ! -z "$LIST" ]
do
SUBLIST="$(echo $LIST | cut -d' ' -f1-10)"
LIST="$(echo $LIST | cut -d' ' -f11-)"
select FILE in $SUBLIST
do
[ -z "$FILE" ] && break
more $FILE
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2004 06:01 AM
01-16-2004 06:01 AM
Re: LS Script
I'm getting syntax error while executing your code. Can you please test and correct it.
Also, my kind request to you is, Do you have any tutorial for reading more about shell scripting.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2004 03:08 PM
01-16-2004 03:08 PM
Re: LS Script
OOOPS Sorry! Your code is working fine on HP-UX, I'm getting syntax error in TRU-64 Unix.
Please tell me where can I read about "select" command and other features of "sh"
.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 06:00 PM
01-18-2004 06:00 PM
Re: LS Script
I'm quite surprised about the syntax error on TRUE64. 'select' is a standard builtin command of the posix shell, so a 'man sh-posix' gives you all I know about it, including PS3 usage and so on ...
Regards.