K
K
Konstantin2016-10-21 12:05:12
bash
Konstantin, 2016-10-21 12:05:12

Why doesn't curl from bash script work?

There is this script:

#!/usr/bin/env bach
curl -o /home/user/local.txt http://localhost/download/server.txt

I run it like this:
$ bash /home/user/my-script.sh
In response I get:
curl: command not found
But if I execute this command immediately from the console:
$ curl -o /home/user/local.txt http://localhost/download/server.txt

then everything is great! file uploaded!
What to do????

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuri, 2016-10-21
@constantant

different paths in PATH
echo $PATH just run
without bash
./my-script.sh

S
sim3x, 2016-10-21
@sim3x

#!/usr/bin/env bach

man bach
No manual entry for bach

#!/bin/bash
#!/usr/bin/env bash

N
Nick, 2016-10-21
@anemuk

In general, it is better to set full paths to commands in scripts.
for example

#!/usr/bin/env bach
/usr/bin/curl -o /home/user/local.txt http://localhost/download/server.txt

Or at the beginning of the script, use the PATH variable.
For example
#!/bin/sh
PATH=/path/to/bin
export PATH
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question