-4

I've already posted this question here:

https://superuser.com/questions/1067609/how-to-run-a-bash-script-via-absolute-path

But I hope that maybe If I duplicate it here, I will get my answer sooner :)

I have a file:

/Users/danylo.volokh/test/test_bash_script.sh

Content is very simple:

#!/usr/bin/env bash
echo "-- print from script"

I'm in folder "danylo.volokh"

This command runs fine:

Danilos-MacBook-Pro:~ danylo.volokh$ test/test_bash_script.sh 
-- print from script

But if I try to run in with absolute path I get an error:

Danilos-MacBook-Pro:~ danylo.volokh$ /test/test_bash_script.sh 
-bash: /test/test_bash_script.sh: No such file or directory

I want to run a command with absolute path from any folder and get the script to be executed.

Community
  • 1
  • 1
Danylo Volokh
  • 4,149
  • 2
  • 33
  • 40
  • 3
    You should fix your understanding of absolute path, absolute path is `/Users/danylo.volokh/test/test_bash_script.sh` not `/test/test_bash_script.sh ` – fghj Apr 20 '16 at 10:14
  • 1
    Please don't cross-post. I can assure you this will only irritate people, not "get your answer sooner"; SuperUser is entirely appropriate for your question. Also, your question at SU *already had two answers* when you posted here. – Piskvor left the building Apr 20 '16 at 10:17
  • Thanks for a good advice. Actually I already got my answer. – Danylo Volokh Apr 20 '16 at 10:20
  • 1
    I'm voting to close this question as off-topic because It is a duplicate of http://superuser.com/questions/1067609/how-to-run-a-bash-script-via-absolute-path Actually I already got -2 for duplicating this. Can I fix it somehow ? – Danylo Volokh Apr 20 '16 at 10:22
  • You could simply delete this question. (Please be aware that *repeatedly* deleting your own question will affect your reputation negatively, though.) – tripleee Apr 20 '16 at 11:44

2 Answers2

2

Your path in incorrect. You should run:

/Users/danylo.volokh/test/test_bash_script.sh
dstronczak
  • 2,406
  • 4
  • 28
  • 41
1

/test/test_bash_script.sh looks for the file from the root directory! Your path should be from the root, not from the current directory.

Try /Users/danylo.volokh/test/test_bash_script.sh.

Sid Sahay
  • 368
  • 5
  • 20