Hy there all. Im new here. Olso new to terminal & bash, but it seams that for me it's much easyer to undarsatnd scripts than an actual programming language as c or anyother languare for that matter.
S-o here is one og my home works s-o to speak.
Write a shell script which:
-only works as a non-root user
-gets a directory or tar archive (*.tar.gz, *.tgz) as the main parameter
-traverses all of it and its subdirectories/archives to find all files containing �much Open, such Stack� in them and print their file names (-n parameter must be given for this)
-if tar archives are found, search for files in them as well without leaving any evidence that you unarchived anything
-print the number of found files (-c parameter must be given)
-check all arguments, both -c and -n may or may not have been given
NOTES:
-check all your parameters at the beginning of the script, and save the �presence� of -n and -c in some variables for later use.
The parameters may come in ANY order so do be aware of that.
you can use `$0 param1 param2 �` to make your script �recursive�.
my curent script looks like this:
!/bin/bash
echo "Hello, "$USER". This script will search all files containing: much Open, such Stack"
abc=$1
echo -n "Enter the search path and pres [ENTER]:"
echo
if [ -d $abc ];then
#find . -type f -print $abc | xargs grep 'much Open, such Stack'
ls -R $abc | xargs cat | grep 'much Open, such Stack'
else
if [ "$abc" == *".tar.gz" ]; then
tar -xvzf $abc
fi
fi
olso i had one more script done wich did made more sens to me at the time, still dose:
#!/bin/bash
echo "Hello, "$USER". This script will search all files containing: much Open, such Stack"
$target
echo -n "Enter the search path and pres [ENTER]:"
read target
echo
if [ -d $target ];then
find . -type f -print $target| xargs grep "much Open, such Stack"
#ls -F $target| grep -v '/' #| xargs cat | grep "much Open, such Stack"
else
if [ "$target" == "*.tar.gz" ]; then
tar -tzf $target
fi
fi
as you can se the codes uses one of the to functions "ls" or "find" ( one being disabled )
My question is this:
why dont i get any kind of output on the second code no mater what path i give it, beeing tar, directory or a txt file, and gain no matter what function i use be it find or ls.
and why dose the first code works? sort of...
Any ideas?