Unable to find the reason for this: bash missing' [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
why am I getting "bash missing'" for this:
function get_xserver ()
{
case $TERM in
xterm )
XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )
;;
aterm | rxvt)
# Find some code that works here. ...
;;
esac
}
This is the exact error:
bash: [: missing `]'

The error is not in the code you posted. The error message:
-bash: [: missing `]'
Means exactly what it says - there is a missing ] character, namely in a [ test ] statement.
Try it:
$ [ 1 -eq 2
-bash: [: missing `]'
You need to identify where the error actually is, and add the missing closing bracket.

Related

raku: Support for utf8-c8 issue in Raku 2020.10 [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 have a file from Wild Wild Web and it contains malformed UTF8. I handled malformed UTF8 in my other codes in previous versions of Raku. In 2020.10 version, I am running into this issue below. Has the support for utf8-c8 changed (this page says it should work, but it doesn't seem to) :
https://docs.raku.org/language/unicode#index-entry-UTF-8_Clean-8
This page has this example:
say slurp($test-file, enc => 'utf8-c8');
Now my code on the command line:
raku -e 'my $a = slurp("zlist"); for $a.lines { .say }'
Malformed UTF-8 near bytes 73 e2 5f at line 55 col 14
in block <unit> at -e line 1
Then using this:
raku -e 'my $a = slurp("zlist", enc => 'utf8-c8'); for $a.lines { .say }'
===SORRY!=== Error while compiling -e
Undeclared routine:
utf8-c8 used at line 1
My code is simple and essentially copied from the example. What am I doing wrong?

Bash string literal comparison to variable failing [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
I have the following simple bash code to test string comparison:
#!/bin/sh
BRANCH="master"
echo $ref
if [[ "$ref" = "refs/heads/$BRANCH" ]]
then
echo "Matches"
else
echo "Do not match"
fi
When I ran the code using export ref=/refs/heads/master && . sample I get the following result:
/refs/heads/master
Do not match
What may be causing the problem?
What is causing the problem is the missing slash in your test: /refs/heads/master is not equal to refs/heads/master!

ruby Unexpected keyword else error [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 6 years ago.
Improve this question
I have this ruby program to parse a CSV file. I am missing a endif somewhere and I cannot figure out.
require 'csv'
prevrow=nil
newarray=Array.new
CSV.foreach("\\\\192.168.0.1\\fe18cb0618cabd41\\ninjatrader\\uniqueside.csv", col_sep: ',') do |row|
if(prevrow==nil)
# do nothing
newarray<<row
prevrow=row
elsif (prevrow!=nil and row[0]!=prevrow[0] )
# do something
newarray<<row
prevrow=row
##count=1
elsif(prevrow!=nil and row[0]=prevrow[0] and ##count<4)
puts "new date"
newarray<<row
prevrow=row
##count++
end
end
removesamedirctiontop4.rb:23: syntax error, unexpected keyword_else
removesamedirctiontop4.rb:27: syntax error, unexpected end-of-input, expecting keyword_end
#count++ is not valid ruby. The final "plus" is expecting another parameter and thinks it's on the next line, so the line ends up being interpreted as...
`#count + +end`
So you have an invalid statement and you lose an end.
Change the offending line to
#count += 1

Bash - Unexpected End of File [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've been working on a bash script to run tests on a program and I can't seem to be able to find the syntax error. When I use -x, it tells me it is expecting a } but I can't find it.
Please see the code underneath.
#!/bin/bash
usagearg() {
echo "You're missing an argument on the command line!" >&2}
usagemiss() {
echo "A file requested in your filestem is missing or cannot be read!" >&2}
if [ ${#} -ne 2 ]; then
usagearg;
exit 1;
fi
x=1
endp=`wc -l ${1}`
end=$((endp+1))
while [ ${x} -ne ${end} ] ; do
# redacted code which isn't related to the issue at hand.
done
I feel like I've closed all the loops and ifs, and all the brackets, so I don't understand why I'm getting the syntax error.
The list of commands inside the braces for the compound command must be terminated by either a semicolon or a newline; the closing brace itself is not sufficient.
Either use
usagearg() {
echo "You're missing an argument on the command line!" >&2; }
or
usagearg() {
echo "You're missing an argument on the command line!" >&2
}
As written, your code treats the right brace as simply another character, and part of the output redirection since there is no intervening whitespace.
As to why this is necessary, you have to go back to how bash defines certain characters. There is the set of metacharacters, which can separate words when unquoted. There is also the set of control operators, which are vaguely defined as performing a "control function". The right brace } is in neither category. (Why? I'm not sure, but I think it's related to the use of braces in parameter expansion (${foo}) which preclude it having otherwise special handling.)

Append to variable within shell script loop [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'm trying to loop over all environment variables in a shell script, and create an HTML query string from ones which match a pattern. Unfortunately, I can't seem to assign to variables in the loop. I've got this:
#!/bin/sh
IFS=$'\n'
TAGS=""
for item in $(printenv)
do
if [[ $item == FOO_TAG_* ]]
then
TAGS = "${TAGS}&${item}"
fi
done
But this gives me
/etc/script.sh: line 9: TAGS: command not found
/etc/script.sh: line 9: TAGS: command not found
How do I fix this?
In the assignment, remove space between variable name and =
TAGS="${TAGS}${item}"

Resources