geoffp154
Posts: 3
Joined: Mon Jan 19, 2015 1:05 pm

command 'filename' not found

Mon Jan 19, 2015 1:53 pm

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

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5621
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: command 'filename' not found

Mon Jan 19, 2015 4:39 pm

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
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
jojopi
Posts: 3268
Joined: Tue Oct 11, 2011 8:38 pm

Re: command 'filename' not found

Mon Jan 19, 2015 5:32 pm

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".

geoffp154
Posts: 3
Joined: Mon Jan 19, 2015 1:05 pm

Re: command 'filename' not found

Mon Jan 19, 2015 5:44 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: command 'filename' not found

Mon Jan 19, 2015 5:50 pm

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
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

geoffp154
Posts: 3
Joined: Mon Jan 19, 2015 1:05 pm

Re: command 'filename' not found

Mon Jan 19, 2015 6:04 pm

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.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5621
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: command 'filename' not found

Mon Jan 19, 2015 6:08 pm

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.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Return to “Beginners”