Flutter command not found inside a shell script
The reason for command not found is cause, you have not given the full path of the flutter program or forgotten to reinit the environment in which you set the PATH Var. To set PATH variable, edit the hidden file .bashrc and append the flutter program's fullpath to PATH variable. Then run the following program after saving the .bashrc file.
source ~/.bashrc
That will reload the .bashrc environment variables.
Alternatively, I suggest you do the following though, for better programming practice.
Do execute this command to find fullpath of flutter program whereis flutter
. Then specify the fullpath/flutter in the shell script. It's always good programming practice to specify fulllpath in programs.
example in shellscript - replace the flutter command with this line: /usr/bin/flutter
Zacktamondo
I maybe can help you, I wish to be able to do so, And I will try my best to do so.
Updated on December 12, 2022Comments
-
Zacktamondo over 1 year
I am creating a shell script to run on my Linux machine when I want to create a new flutter project. But when I try to put
flutter create appName
inside the shell script it gives me./flutter.sh: line 9: flutter: command not found
I added flutter to path so I can run
flutter create appName
from the terminal with no problem at all. Thank you for your help. -
Zacktamondo almost 5 yearsThank u for the answer but the thing is when I put flutter command in the terminal the command execute perfectly which means my paths are ok right?
-
Magnus Melwin almost 5 yearsThat happens because u set the PATH variable in the terminal and didn't export the PATH variable like 'export PATH' with the export command. So the bash environment for the shell script is unable to find it. And shell scripts tend to run in a new shell and not in your terminals shell. This is a very common mistake with shell programs
-
Magnus Melwin almost 5 yearsSimply replace ur flutter command in the shell script with its fullpath/flutter program...thats the easiest way to correct this.
-
Charles Duffy almost 5 years@MagnusMelwin, "easiest", maybe, but it makes the script specific to that one host and the specific place it has the program in question installed; hardly good practice. If you wanted a host-specific fix, putting
PATH=$PATH:/path/to/directory/containing/flutter
at the top will at least not break other systems, but will still fix the current one. -
Magnus Melwin almost 5 years@Charles - You are quite right on that, though. Although, from a security point of view - its safer to use fullpaths - u can always use the whereis command to find the fullpath of the flutter program and use the output in the shell scripts itself using the backtick and variables. example: myprogram=
whereis flutter
-
Charles Duffy almost 5 years@MagnusMelwin, the shell itself internally caches the results of PATH updates, so using
whereis
(an external command not standardized by POSIX) reduces your portability and adds no value. (To do a PATH lookup in a POSIX-standardized way, usecommand -v
-- though even then, paying the cost of a subshell to store its output is suboptimal).