1

I am trying to run a shell script with the bellow content

ns script.tcl
sleep 100

the command ns works fine when typing in terminal but says:

ns : not found

when runing from the shell script.

  • I'm guessing ns is an alias, or if it's from the ns2 package, it is not in your $PATH. Please edit your question and include i) the output of type ns; ii) the output of echo $PATH; iii) your entire script. Is there a shebang line? – terdon Sep 6 '15 at 13:09
1
#!/bin/bash
ns script.tcl
sleep 100

What happens if you try running the script with a proper interpreter declaration at the top? This could possibly load your $PATH, which is how your terminal knows where to find ns.

If that doesn't work, you could try the following:

#!/bin/bash
/usr/bin/ns script.tcl
sleep 100

You should probably point to the path/directory in which your script.tcl is in. If it's in the same directory as the bash script, then you'd be fine. But what would happen if your CWD had script.tcl? It's best to be specific when scripting. I was able to tell where ns was located by running which ns in my terminal.

  • it says : ns: command not found – user329907 Sep 1 '15 at 17:25
  • yes the script.tcl is in the same directory as the .sh file is. and i've been using the exact same system when i had fedora 10 and it was ok. – user329907 Sep 1 '15 at 17:29
  • The problem is probably that you're $PATH is not being set correctly. Did you try the second example I posted? – earthmeLon Sep 1 '15 at 17:30
  • the path is set correctly because when i run ns in terminal it works perfectly. the path is "/home/myusername/ns-allinone-2.35/ns-2.35/ns". when i tried your recommendation to specify the path like this "#!/bin/bash /home/nima/ns-allinone-2.35/ns-2.35/ns script.tcl sleep 100" the command is working but since there is another ns command inside the script.tcl file the problem still remains. – user329907 Sep 1 '15 at 17:45
  • Add that directory to your $PATH variable within bash. Be sure that it comes BEFORE the other paths (prepend to existing $PATH). Then, your user will prefer that binary to the system binary. – earthmeLon Sep 8 '15 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.