mercredi 15 mai 2019

i don't know if my shell script is correct

i have a homework using for loop but i'm not quite understand the task that i have to do in there. i wrote a script but i feel like it's not a correct script. please help!

here is the question:

Write a shell script to list out the contents of any directory, and indicate for each file (including invisible ones) whether the file is a directory, a plain file, and whether it is public and/or executable to this process

#!/bin/bash

if [ $# -lt 1 ] ; then
echo " file doesn't exist"
echo 
echo " variable needed to run a command"
fi
echo ---------------------------------------------
echo ---------------------------------------------

for i in $*
do
if [ -f $i ]; then 
echo " it's a file";
echo "THIS IS A LIST OF FILE and DIRECTORY in $i"
ls -a $i
fi
done
echo -----------------------------------------
if [ -d $i ]; then

echo "directory" ;
echo "THIS IS A LIST OF FILES AND DIRETORY in $i"

ls -a $i
fi
echo ------------------------------------------
if [ -x $i ]; then
echo "executable"
echo "THIS IS A LIST OF EXECUTABLE FILE IN $i" 
ls -x $i
fi
echo -----------------------------------------
if [ -r $i ]; then
echo "this file is a public file"
else "this is a private file" 
fi

#!/bin/bash

if [ $# -lt 1 ] ; then
echo " file doesn't exist"
echo 
echo " variable needed to run a command"
fi
echo ---------------------------------------------
echo ---------------------------------------------

for i in $*
do
if [ -f $i ]; then 
echo " it's a file";
echo "THIS IS A LIST OF FILE and DIRECTORY in $i"
ls -a $i
fi
done
echo -----------------------------------------
if [ -d $i ]; then

echo "directory" ;
echo "THIS IS A LIST OF FILES AND DIRETORY in $i"

ls -a $i
fi
echo ------------------------------------------
if [ -x $i ]; then
echo "executable"
echo "THIS IS A LIST OF EXECUTABLE FILE IN $i" 
ls -x $i
fi
echo -----------------------------------------
if [ -r $i ]; then
echo "this file is a public file"
else "this is a private file" 
fi

Aucun commentaire:

Enregistrer un commentaire