Page 1 of 1

command 'filename' not found

Posted: Mon Jan 19, 2015 1:53 pm
by geoffp154
I've had my Pi a couple of weeks now and currently am working through some simple Picam projects.
I'm using BASH, Python and CLI and most stuff seems to be going ok.
I've hit a problem with an example project which makes use of the filename command to set up a ddmmyy filename within a bash script.
I get the message
./timelapse.sh: line 6: filename: command not found
I've issued the commands

Code: Select all

sudo apt-get update && sudo apt-get upgrade
and these have worked successfully.

Command

Code: Select all

sudo find / -name filename 
comes up with a null response

I'm sure the answer is pretty simple, but I can't see what to do next

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 4:39 pm
by FTrevorGowen
geoffp154 wrote:I've had my Pi a couple of weeks now and currently am working through some simple Picam projects.
I'm using BASH, Python and CLI and most stuff seems to be going ok.
I've hit a problem with an example project which makes use of the filename command to set up a ddmmyy filename within a bash script.
I get the message
./timelapse.sh: line 6: filename: command not found
Can you post the output of head ./timelapse.sh (ie. the first ten lines of the bash script) within "Code" tags?** AFAIK, there is no filename command as such, and I suspect that the word "filename" is just part of the error message.
Trev.
** Like this example:

Code: Select all

trevor@BlueElf:~$ head bar_test1.sh 
#!/bin/bash
#Slice of PI/O Bar Test 1

#Set Bank A to be outputs
i2cset -y 1 0x20 0x00 0x00
#Set Bank B to be outputs
i2cset -y 1 0x20 0x01 0x00
#Set all used A bits high
i2cset -y 1 0x20 0x12 0xc0
#Set all used B bits high

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 5:32 pm
by jojopi
To set a variable in sh, the syntax is like:

Code: Select all

filename="image.jpg"
It is essential to have no spaces either before or after the equals. In particular, if you have a space before the equals, you are instead running the command "filename" with argument "=image.jpg".

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 5:44 pm
by geoffp154
Hi Trev
here is my code - borrowed from Eben Upton's RPi user guide ...

Code: Select all

#! /bin/bash
#RPi User Guide pp245
while true
        do
        echo $PATH
        filename = `date +%Y%m%dT%H%M%S`.jpg
        raspistill -w 1920 -h 1080 -t 0 -o $filename
        echo Image captured
        sleep 30
        done

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 5:50 pm
by ripat
No space before and after the = sign.

Code: Select all

filename=`date +%Y%m%dT%H%M%S`.jpg

# or better
filename=$(date +%Y%m%dT%H%M%S).jpg

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 6:04 pm
by geoffp154
I have removed the spaces around the "=" and the code works fine. Using spaces around = is an old habit, but I'll stop doing that in these cases, and watch out for it as potential cause of errors.
Thanks a million to ripat, jojopi and Trev for getting back to me so quickly and for being so helpful.

Re: command 'filename' not found

Posted: Mon Jan 19, 2015 6:08 pm
by FTrevorGowen
geoffp154 wrote:Hi Trev
here is my code - borrowed from Eben Upton's RPi user guide ...

Code: Select all

#! /bin/bash
#RPi User Guide pp245
while true
        do
        echo $PATH
        filename = `date +%Y%m%dT%H%M%S`.jpg
        raspistill -w 1920 -h 1080 -t 0 -o $filename
        echo Image captured
        sleep 30
        done
(Almost) as I suspected - "filename" was not a "command" but a script variable. I see @ripat has provided solutions .
It always helps to provide full details of the script/code etc. in the region(s) indicated by the error message(s).
Trev.