This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
Closed 7 years ago.
OS: Ubuntu 14.04
I created a test file called test and in it I have:
#!/bin/bash
NEW_VALUE = "/home/"
echo $NEW_VALUE
chmod +x test
./test
Produces the following:
./test: line 2: NEW_VALUE: command not found
Any ideas why this is not working?
In Bash you can't have any space around the = sign when assigning a variable.
Any space will end the assignment, even after the =, e.g.:
test_var=this is bad
#=> is: command not found
#CharlesDuffy's comment explaining why this happens
Check this link for more information on variable assignment in bash: http://wiki.bash-hackers.org/scripting/newbie_traps#setting_variables
Remove the white space while assigning then it'll work fine. just like:
#!/bin/bash
NEW_VALUE="/home/"
echo $NEW_VALUE
Related
This question already has answers here:
Getting "command not found" error in bash script
(6 answers)
Closed 3 years ago.
I'm having a BASH script:
#!/usr/bin/env bash
PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
YAML=$(envsubst < ${PATH}/test.yml)
echo "${YAML}"
It results:
./test.sh: line 5: envsubst: command not found
I see that having a variable inside command substitution causes such error.
If I'm not using any:
YAML=$(envsubst < ./test.yml)
Then I'm having an expected successful script execution.
I've tried different syntax using quotes all over the place, but nothing helped.
How do I successfully use variable inside command substitution?
Bash version:
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
UPDATE: A duplicate question. Found an answer here:
https://stackoverflow.com/a/5642584/5935309
The problem is that you are changing PATH, which is used by Bash internally to define where to look for programs (and in which order).
You changed PATH to only contain the current working dir, and that's not where envsubst is located.
The solution is to use something different than PATH, like FILE_PATH.
This question already has answers here:
Why should there be spaces around '[' and ']' in Bash?
(5 answers)
Closed 3 years ago.
I'm looking at a bash script with this:
PARAMS="%1;$1;$2;$3;$4;$5;$6;$7;$8;$9"
As I understand it, the parameters that are passed in on script execution will be added to this list.
When I run this:
runscript.sh CONFIG 2>&1
I see this error:
line 76: [[%1;CONFIG;;;;;;;;: command not found
where line 76 contains this:
if [[$PARAMS =~ "CONFIG" ]];
What does the %1 mean and how should I run the script to get it to work?
I didn't have a space after the [[. Once added the script worked.
This question already has answers here:
How to execute a bash command stored as a string with quotes and asterisk [duplicate]
(5 answers)
Command not found error in Bash variable assignment
(5 answers)
Closed 4 years ago.
I have an application in Unix. I use the below command to connect to it:
./application -a "connect"
I want to do the same through the shell script, for which i assigned the command line to a variable like:
newcommand = './application -a "connect"'
$newcommand
But this is not working.
However the first part of the code is working. i.e.,:
newcommand = "./application"
$newcommand
Can anyone point out what i am missing.
Believe it or not, this:
newcommand = "./application"
...has the shell run the command, newcommand with the arguments, =, and ./application.
In shell simple assignments cannot have any unprotected whitespace or they'll be interpreted as a command.
Consider:
newcommand=./application
$newcommand
...notice that there's no space around the = sign in the assignment.
This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
How to assign the output of a Bash command to a variable? [duplicate]
(5 answers)
Closed 4 years ago.
I want to write a bash script to get block count . It is giving error
./script.sh: line 4: =: command not found
Below is my script
#!/bin/bash
# getblockcount
$blockcount = bitcoin-cli getblockcount
echo $blockcount
Kindly tell what is wrong .
There should not be space around the operator.. So remove the space around = and thing should work. Also there are some other bits.. Here is the corrected one.. Ensure command bitcoin-cli getblockcount from terminal gives right result.
#!/bin/bash
# getblockcount
blockcount=$(bitcoin-cli getblockcount)
echo $blockcount
This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
Closed 7 years ago.
I have a shell script that will let me access global variables inside the script, but when I try to create my own, it responds with: command not found.
#!/bin/bash
J = 4
FACE_NAME = "eig$J.face"
USER_DB_NAME = "base$J.user"
When I run the above script I get:
./test1.sh line 2: J: command not found
./test1.sh line 3: FACE_NAME: command not found
./test1.sh line 4: USER_DB_NAME: command not found
Any ideas?? I'm using Cygwin under Windows XP.
Try this (notice I have removed the spaces from either side of the =):
#!/bin/bash
J="4"
FACE_NAME="eig$J.face"
USER_DB_NAME="base$J.user"
Bash doesn't like spaces when you declare variables - also it is best to make every value quoted (but this isn't as essential).
It's a good idea to use braces to separate the variable name when you are embedding a variable in other text:
#!/bin/bash
J=4
FACE_NAME="eig${J}.face"
USER_DB_NAME="base${J}.user"
The dot does the job here for you but if there was some other character there, it might be interpreted as part of the variable name.
dont' leave spaces between "="
J=4
FACE_NAME="eig${J}.face"
USER_DB_NAME="base${J}.user"