Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -ne 3 ]
- then
- echo "USAGE: `basename $0` imenik bajti some_file.txt"
- exit 1
- fi
- if [ ! -d $1 ]
- then
- echo "Imenikot prosleden kako argument ne postoi"
- exit 1
- fi
- #there should also be a check if the second argument is a number but I did not find that part enteratining so let's hope it's a number
- file_name=`echo $3 | sed 's/\.txt//'`
- if [ ! -f $3 ]
- then
- touch $3
- else
- rm $3
- touch ${file_name}_moved.txt
- fi
- #get all .sh files that weigh less than 150B from argument1 directory
- SCRIPTS=`ls -R $1 | awk '$4<150 && $10~/\.sh$/ {print $10}'`
- for script in $SCRIPTS
- do
- #make sure they are executable by the user
- chmod $script u+x
- result=`./$script`
- #just tryna detect whether they require to be called with arguments or not
- #I know this segment looks kinda goofy but my hungry ass could not think of any other way atm
- #I am not sure whether we should learn that by the output message or like the exit call or something
- #if anyone knows more to it simply DM me :3
- temp=`$result | grep USAGE`
- if [ -f $3 ]
- then
- if [ "$result" == "$temp" ]
- then
- echo "$script se povikuva so argumenti" >> $3
- else
- echo "$script se povikuva bez argumenti" >> $3
- else
- if [ "$result" == "$temp" ]
- then
- echo "$script se povikuva so argumenti" >> ${file_name}_moved.txt
- else
- echo "$script se povikuva bez argumenti" >> ${file_name}_moved.txt
- fi
- done
- if [ -f $3 ]
- then
- cat $3
- else
- cat ${file_name}_moved.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement