Linux 1) Write a script which takes 3 files as arguments. If these files have a
ID: 3811263 • Letter: L
Question
Linux
1) Write a script which takes 3 files as arguments. If these files have a total of more than 100 lines it displays the message "Too long" and otherwise it concatenates them and saves the result in a file called done . Your script can only have one if/else and no variables
2)We've seen operations [ - e object] to test if something exists. More specific operations such as [ - f object] or [ - d object] will test if it exists and is a file or a directory, respectively. There are a few more like that: - r, - w, and - x will check whether the file has the permissions r, w, or x for example. The - O will check if it's owned by the current user. Write a script that takes a file as argument. If the file doesn’t exist, it says so to the user. If the file exists, it displays what permissions are currently turned on for this file, and tells the user whether he/she can change them
Explanation / Answer
#!/bin/bash
if ! [ -f $1 ];
then
echo "$1 Not Exist"
exit 0
else
echo ""
fi
if ! [ -f $2 ];
then
echo "$2 not Exist"
exit 0
fi
if ! [ -f $3 ];
then
echo "$3 not Exist"
exit 0
fi
if ! [ -r $1 ];
then
echo "$1 has read permission issue"
exit 0
fi
if ! [ -r $2 ];
then
echo "$2 has read permission issue"
exit 0
fi
if ! [ -r $3 ];
then
echo "$3 has read permission issue"
exit 0
fi
if ! [ -O $1 ];
then
echo "$1 has ownership permission issue"
exit 0
fi
if ! [ -O $2 ];
then
echo "$2 has ownership permission issue"
exit 0
fi
if ! [ -O $3 ];
then
echo "$3 has ownership permission issue"
exit 0
fi
if [[ $(cat $1 $2 $3| wc -l) -gt 100 ]];
then
echo "Too Long"
else
cat $1 $2 $3>done
echo "File copied successfully!!!"
fi
exit 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.