# rc script "grep not found"



## ShyRain (Sep 5, 2013)

Hi, 

I am trying to write a bash script for rc(8) but I got an error such as:

My example code part:

```
#!/bin/sh
. /etc/rc.subr

diskCheck=`/sbin/mount | /usr/bin/grep zfs`
echo "Result : "${diskCheck}
echo "Result2: "$(which grep)
echo "Result3: "$(/usr/bin/which grep)
```

Errors:

```
eval: /usr/bin/grep: not found
Result :
which: not found
Result2:
eval: /usr/bin/which: not found
Result3:
```


----------



## tmw (Sep 5, 2013)

Hey,

Did you check where you have grep?


----------



## SirDice (Sep 5, 2013)

ShyRain said:
			
		

> I am trying to write bash script for rc(8) but I got an error such as:


That's not a bash(1) script. It's a Bourne shell script. Remove the _bashisms_ or actually run it with shells/bash instead of sh(1).


----------



## ShyRain (Sep 5, 2013)

tmw said:
			
		

> Hey,
> Did you check where you have grep ?



In my code, `"echo "Result2: "$(which grep)"`, result2 is empty :S

But in my terminal:

```
[root@HP ~]# which grep
/usr/bin/grep
```


----------



## ShyRain (Sep 5, 2013)

SirDice said:
			
		

> That's not a bash(1) script. It's a shell script. Remove the _bashisms_ or actually run it with shells/bash instead of sh(1).



You are also right but;


```
[root@HP ~]# sh
# which
usage: which [-as] program ...
# /usr/bin/which grep
/usr/bin/grep
```


----------



## tmw (Sep 5, 2013)

Hey,

This script works for me. Try with -x to see what this script is doing.


----------



## ShyRain (Sep 5, 2013)

Normally it is working on the terminal but it is not working on startup. I think I have to change this script's working order because I think this works before the system is mounted. How can I change the rc.d scripts' work order?


----------



## ShelLuser (Sep 5, 2013)

You need to look into the rc.d(8) manual page. Basically you need to use rcorder keywords in your script which will help the rc structure to determine the right order to use, in your case you'd want to look at REQUIRE.

I haven't looked into this in depth myself, but solely based on what I read in the manual page and looking at some other scripts (_always_ look at how others are doing it) you might benefit from using something like:


```
#!/bin/sh

# REQUIRE: LOGIN

. /etc/rc.subr
```

PS (edit): Also look into the rcorder(8) manual page for more information about those keywords.


----------



## ShyRain (Sep 5, 2013)

ShelLuser said:
			
		

> You need to look into the rc.d(8) manual page. Basically you need to use rcorder keywords in your script which will help the rc structure to determine the right order to use, in your case you'd want to look at REQUIRE.
> 
> I haven't looked into this in depth myself, but solely based on what I read in the manual page and looking at some other scripts (_always_ look at how others are doing it) you might benefit from using something like:
> 
> ...


Yes this is the solution, I add

```
# REQUIRE: usr
```
and it works!


----------

