sh file not found

Forum rules
Before you post please read how to get help
Post Reply
TryThisMint
Level 1
Level 1
Posts: 2
Joined: Sat Aug 03, 2019 12:02 pm

sh file not found

Post by TryThisMint » Sat Aug 03, 2019 12:27 pm

Hello, I'm trying to run a script on Linux Mint 18.3 xfce x64 virtualizing it on VirtualBox. Basically this script search in a directory the passed string in every .txt file with more than num string. Than print the name of the directory with the maximum number of .txt file that fulfill the request. Here is the code:

cercafile.sh

Code: Select all

#!/bin/sh

if test $# -ne 3
then
	echo "I'm using cercaFile string dir num"
	exit 1
fi

if test -z $1
then
	echo FIrst parameter must be a string
	exit 2
fi

str=$1
shift

case $1 in
	/*) ;;
	*) echo Second parameter mus be an absolute path
	   exit 3
esac
	
if test ! -d $1
then
	echo Second parameter must be a directory
	exit 4
fi

dir=$1
shift

case $1 in
	*[!0-9]*) echo Third parameter must be a number
		  exit 5;;
esac

num=$1
shift

PATH=$PATH:`pwd`
export PATH
> /tmp/.maxcounter.tmp
> /tmp/.maxdir.tmp

ricerca.sh "$str" "$dir" $num
echo The directory with maximum number of file that fulfiil the request is `cat /tmp/.maxdir.tmp` with `wc -l < /tmp/.maxcounter.tmp` occurrences
rm -f /tmp/.maxcounter.tmp
rm -f /tmp/.maxdir.tmp
ricerca.sh

Code: Select all

#!/bin/sh

cd "$2"
>/tmp/.counter.tmp
for i in `ls *.txt 2> dev/null`
do
	if test -f "$i" -a -r "$i" -a `grep -c "$1" "$i" -gt $3`
	then 
		echo "$i" >> /tmp/.counter.tmp
	fi
done

if test `wc -l < /tmp/.counter.tmp` -gt `wc -l < /tmp/.maxcounter.tmp`
then
	mv /tmp/.counter.tmp /tmp/maxcounter.tmp
	echo `pwd > /tmp/.maxdir.tmp`
fi
rm -f /tmp/.counter.tmp

for dir in *
do
	if test -d "$dir" -a -x "$dir"
	then
		ricerca.sh "$1" "$dir" $3
	fi
done
But when I try from terminal to run it with

Code: Select all

sh cercafile.sh do /home/mint 5 
it gives me an error - > cercafile.sh: 47: cercafile.sh: ricerca.sh: not found.
The files are actually in /home/mint, but also if I move they in Desktop or another folder I keep obtaining this error. I've got every file permission. Thanks in advance.

deepakdeshp
Level 15
Level 15
Posts: 5667
Joined: Sun Aug 09, 2015 10:00 am

Re: sh file not found

Post by deepakdeshp » Sat Aug 03, 2019 1:07 pm

cd to the folder in which the script is there.
Try

Code: Select all

  sh ./cercafile.sh do /home/mint 5  
Please copy pate the command.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
Regards,
Deepak

I am using Mint 19.2 Cinnamon 64 bit with AMD A8/7410 processor . Memory 8GB

JeremyB
Level 20
Level 20
Posts: 10893
Joined: Fri Feb 21, 2014 8:17 am

Re: sh file not found

Post by JeremyB » Sat Aug 03, 2019 1:14 pm

The line in cercafile.sh

Code: Select all

ricerca.sh "$str" "$dir" $num
Might need to be

Code: Select all

/home/mint/ricerca.sh "$str" "$dir" $num

User avatar
smurphos
Level 12
Level 12
Posts: 4118
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: sh file not found

Post by smurphos » Sun Aug 04, 2019 2:58 am

+1 to JeremyB's post.

Hint,

Consider storing your personal scripts in ~/bin or ~/.local/bin. Neither directory exists by default but once created and after one logoff and log back in the directories are added to you $PATH and scripts can be launched from the command line or from another script by command name only rather than full path.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

TryThisMint
Level 1
Level 1
Posts: 2
Joined: Sat Aug 03, 2019 12:02 pm

Re: sh file not found

Post by TryThisMint » Mon Aug 05, 2019 5:41 am

deepakdeshp wrote:
Sat Aug 03, 2019 1:07 pm
cd to the folder in which the script is there.
Try

Code: Select all

  sh ./cercafile.sh do /home/mint 5  
Please copy pate the command.
smurphos wrote:
Sun Aug 04, 2019 2:58 am
+1 to JeremyB's post.

Hint,

Consider storing your personal scripts in ~/bin or ~/.local/bin. Neither directory exists by default but once created and after one logoff and log back in the directories are added to you $PATH and scripts can be launched from the command line or from another script by command name only rather than full path.
JeremyB wrote:
Sat Aug 03, 2019 1:14 pm
The line in cercafile.sh

Code: Select all

ricerca.sh "$str" "$dir" $num
Might need to be

Code: Select all

/home/mint/ricerca.sh "$str" "$dir" $num
Still having the same error even if I've done everything you suggested

Post Reply

Return to “Scripts & Bash”