Hi-

Was wondering if I could get help with a shell script I am writing to read in 10 -20 directories from a filesystem and then pause, press any key and then read in another 10 or 20 directories and pause again until I read them all.

Here is my code - a bit embarrassing...

#!/bin/bash

DIRS="/data/cusserv/"

for D in $DIRS
do
  count=0
  ls -lt $D | awk '{print $9}'
  count=`expr $count + 1`
  echo "Argument number $count : $1 "
  read $I
done

All my directories are listed at once - wanted to step thru them 10-20 at a time.

Thanks for any help!

-P

Recommended Answers

All 2 Replies

how about piping it through a pager? less -y20 will page 20 lines at a time.

Was wondering if I could get help with a shell script I am writing to read in 10 -20 directories from a filesystem and then pause, press any key and then read in another 10 or 20 directories and pause again until I read them all.

#!/bin/bash

DIRS="/data/cusserv/"

for D in $DIRS


Why are you using a loop? There is only one value in $DIRS.

do
  count=0
  ls -lt $D | awk '{print $9}'


You don't need awk:

ls -t $D
count=`expr $count + 1`


In a POSIX shell (such as BASH) you don't need an external command to do integer arithmetic:

count=$(( $count + 1 ))
echo "Argument number $count : $1 "
  read $I
done

All my directories are listed at once - wanted to step thru them 10-20 at a time.

ls -t "$DIRS" | awk '(NR % 10) == 0 { system("read < /dev/tty") }1'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.