Shell variable is being treated as command [closed] - linux

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have written this small script to compare file name with the files in one folder and copy them to another folder if they do not exist in the first one. Please refer code. But for some reason Ubuntu 15.04 is treating my variable as command and giving me following error:
./COPY_FILES.sh: line 8: FILE_EXIST_IN_SUPER_STRING: command not found
while read NAME1
do
FILE_EXIST_IN_SUPER_STRING = 0
while read NAME2
do
if [ "$NAME1" == "$NAME2" ]
then
FILE_EXIST_IN_SUPER_STRING = 1
fi
done < file_superstring.txt
if [ "$FILE_EXIST_IN_SUPER_STRING" == 0 ]
then
cp Master/"$NAME1" Non-SuperString/"$NAME1"
fi
done < Total_files.txt

Third line should have no spaces.
It should be:
FILE_EXIST_IN_SUPER_STRING=0

Related

Running C Program script in Linux gives error: syntax error near unexpected token `(' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I keep getting this error on Linux while running a C program.
line3: syntax error near unexpected token (' line3: int main()'
Here is the simple code:
#include<stdio.h>
#include<string.h>
int main()
{
printf("Hello");
return 0;
}
You have to compile c code. First remove the #!/bin/bash from the top. Then try this:
gcc -o script script.c
this will build your program and output it to a binary file called script.
you can then run it like this:
./script

AWK command not working in linux but works in mac [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Can someone tell me what am I doing wrong here? It seems to work on my mac shell but does not work on linux box it seems. Looks like different version of awk? I want to make sure my code works on the linux version.
echo -e "${group_values_with_counts}" | awk '$1>='${value2}' { print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }'
21:19:41 awk: $1>= { print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }
21:19:41 awk: ^ syntax error
You're trying to pass the value of a shell variable into awk the wrong way and using a non-portable echo. The right way (assuming value2 doesn't contain any backslashes) is:
printf '%s\n' "$group_values_with_counts" |
awk -v value2="$value2" '$1>=value2{ print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }'
If value2 can contains backslashes and you want them treated literally (e.g. you do not want \t converted to a tab character) then you need to pass it in using ENVIRON or ARGV. See http://cfajohnson.com/shell/cus-faq-2.html#Q24.

Shell script to capture the updated part in a file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
file 1
23
1030042388
0
1.000000000000000
739203
0.041035795614451
754163
0.010276519532845
827907
0.147827256904898
2961752
0.017365353262416
3006283
The above file gets updated as
file1
23
1030042388
0
1.000000000000000
739203
0.041035795614451
754163
0.007314889610240
130695515
0.010276519532845
827907
0.147827256904898
2961752
0.017365353262416
3006283
0.000185740873681
13483011
0.028083838182834
13497795
0.011287502580049
13512752
0.219960404756292
13512755
Note updation can happen any where in the file, and numbers/lines should not be sorted
i need to capture only the update part in to other file
file 3
0.007314889610240
130695515
0.000185740873681
13483011
0.028083838182834
13497795
0.011287502580049
13512752
0.219960404756292
13512755
Could you please help me in this
Thanks
Using comm:
% comm -13 <(sort f1.txt) <(sort f2.txt)
0.000185740873681
0.007314889610240
0.011287502580049
0.028083838182834
0.219960404756292
130695515
13483011
13497795
13512752
13512755

syntax error near unexpected token `else' [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to Linux and Shell scripting, so please help me with some patience.
Could you please let me know how to fix this problem?
Below is the error
./test.sh: line 5: syntax error near unexpected token `else'
./test.sh: line 5: `else'
Below is the simple if statment in shell scripting.
I use vi editor
#!/bin/bash -x
age=10;
if(age -lt 13)
echo "$age"
else
echo "xx"
Any information is highly appreciable.
Matt
Don't end a statement with ;. This is not c/c++/java program.
Conditions in script are enclosed with [] not ()
Please read how to use if statement/syntax. Do google and then try.
Syntax of if:
if [ conditional expression ]
then
#statements
...
fi
So your program is:
#!/bin/bash
age=10
if [ $age -lt 13 ]
then
echo "something"
else
echo "some other thing"
fi

Bash file existence checking missing ] [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am attempting a simple file existence check in my bash script:
FILE_TO_CHECK=/home/username/path/to/file
if [ ! -f $FILE_TO_CHECK]; #line 9 in actual script
then
echo File not found.
fi
Seems simple enough to me, but I'm getting the following error and I don't know why:
/path/to/script: line 9: [: missing `]'
I'm not exactly a bash expert, but I was pretty sure a backtick is not necessary in this context. What gives?
Missing space before the closing ].
You have to understand that [ is a command and everything following it, until the ;, are its arguments. Command [ expects its last argument to be ]. But if you omit the space, then ] becomes the last character of the previous argument.
It might seem that [ ] is part of the if syntax. It's not the case. if has to be followed by any command, and if evaluates its exit status.
if true; then foo; fi
In the above line true is a command too.
$ which true
/bin/true
true is a command with the sole purpose of always having a true (0) exit status.
You could also try:
if (test ! -f $FILE_TO_CHECK);
or
if !(test -f $FILE_TO_CHECK);
as [ is a shorthand for the test command.

Resources