i need to print the file names of all files having .txt extension of a given directory after converting to uppercase letters. The input (directory name) should be given as command line argument. The script will also check whether sufficient arguments are passed or not and whether the argument is a directory or not

i tried using this code

if [ -f $filename ]
tr "[a-z]" "[A-Z]" <$filename

but i dint get output

Recommended Answers

All 3 Replies

What did you get?

Hi,

Is this answer for your question?

---------------------------------------------------------
#!/bin/sh

if [ -d $1 ]
then
echo "Yes this is a directory"
else
echo "No this is not a directory"
fi

cd $1
echo "dir is: `pwd`"

FILES=`ls *.txt`

for i in $FILES
do
echo $i | tr '[:lower:]' '[:upper:]'
done
-----------------------------------------------------------------------------

correct me if my understanding is wrong?

BR/ KMat

i need to print the file names of all files having .txt extension of a given directory after converting to uppercase letters. The input (directory name) should be given as command line argument. The script will also check whether sufficient arguments are passed or not and whether the argument is a directory or not

i tried using this code

if [ -f $filename ]
tr "[a-z]" "[A-Z]" <$filename

but i dint get output

if [ -d $1 ]
then
echo "Yes this is a directory"
else
echo "No this is not a directory"
fi

cd $1
echo "dir is: `pwd`"

KMat, what happens when $1 is not a directory? What do you think will happen when you do cd $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.