Question: Hello, please convert the following script code into C Language, Thank you. #!/bin/bash if [ $# -lt 2 ];then echo not enough args! exit
Hello, please convert the following script code into C Language, Thank you.
#!/bin/bash
if [ $# -lt 2 ];then
echo "not enough args! "
exit 1
fi
tarfilename=$2
case $1 in
-o)
# checking if any file provided
if [ $# -lt 3 ]; then
echo "no file provided ,provide atleast one file "
exit 1
fi
echo "creating tar file $tarfilename"
# creating empty tar file
tar -cf $tarfilename -T /dev/null
# skipping first two args
shift
shift
# looping through files
for file in "$@"
do
# appending to tar file
tar -rf $tarfilename $file
done
;;
-t)
# printing the file from tar file
tar -tvf $tarfilename
;;
-x)
# unpacking the tar file
tar -xf $tarfilename
;;
*)
echo "invalid option $1"
echo "use -o or -t or -x"
exit 1
esac # end of script
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
