running a shell script from another script

2019-03-03 15:17发布

I have a script in unix that looks like this:

#!/bin/bash

gcc  -osign sign.c

./sign < /usr/share/dict/words | sort | squash > out

Whenever I try to run this script it gives me an error saying that squash is not a valid command. squash is a shell script stored in the same directory as this script and looks like this:

#!/bin/bash
awk -f squash.awk

I have execute permissions set correctly but for some reason it doesn't run. Is there something else I have to do to make it able to run like shown? I am rather new to scripting so any help would be greatly appreciated!

1条回答
劳资没心,怎么记你
2楼-- · 2019-03-03 15:27

As mentioned in @Biffen's comment, unless . is in your $PATH variable, you need to specify ./squash for the same reason you need to specify ./sign.

When parsing a bare word on the command line, bash checks all the directories listed in $PATH to see if said word is an executable file living inside any of them. Unless . is in $PATH, bash won't find squash.

To avoid this problem, you can tell bash not to go looking for squash by giving bash the complete path to it, namely ./squash.

查看更多
登录 后发表回答