How to check not starts with condition in if statement?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to check the condition like below. Line should not starts with #
symbol:
if[ ! ["$Line" == "#*"] ]; then
But this is not working.
shell-script
add a comment |Â
up vote
0
down vote
favorite
I want to check the condition like below. Line should not starts with #
symbol:
if[ ! ["$Line" == "#*"] ]; then
But this is not working.
shell-script
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to check the condition like below. Line should not starts with #
symbol:
if[ ! ["$Line" == "#*"] ]; then
But this is not working.
shell-script
I want to check the condition like below. Line should not starts with #
symbol:
if[ ! ["$Line" == "#*"] ]; then
But this is not working.
shell-script
shell-script
edited Aug 31 at 2:28
Steven Penny
2,31921635
2,31921635
asked Jun 30 '16 at 4:37
Rajagopalarao
32
32
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.
You can negate equality operator instead:
if [[ "$LINE" != #* ]]; then echo yes; fi
Take also closer look to spaces surrounding brackets.
add a comment |Â
up vote
0
down vote
Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.
case $line in
"#"*) echo no
esac
The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.
If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in
case $line in
"#"*) echo no ;;
*) echo yes
esac
... and the code for a pattern may be empty:
case $line in
"#"*) ;;
*) echo yes
esac
The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:
if [[ $line != "#"* ]]; then
echo yes
else
echo no
fi
In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:
if ! [[ $line =~ ^# ]]; then
echo yes
else
echo no
fi
or
if [[ $line =~ ^[^#] ]]; then
echo yes
else
echo no
fi
If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:
awk '/^[^#]/ print yes ' <inputfile
Related:
- Why is using a shell loop to process text considered bad practice?
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.
You can negate equality operator instead:
if [[ "$LINE" != #* ]]; then echo yes; fi
Take also closer look to spaces surrounding brackets.
add a comment |Â
up vote
1
down vote
There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.
You can negate equality operator instead:
if [[ "$LINE" != #* ]]; then echo yes; fi
Take also closer look to spaces surrounding brackets.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.
You can negate equality operator instead:
if [[ "$LINE" != #* ]]; then echo yes; fi
Take also closer look to spaces surrounding brackets.
There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.
You can negate equality operator instead:
if [[ "$LINE" != #* ]]; then echo yes; fi
Take also closer look to spaces surrounding brackets.
edited Jun 30 '16 at 5:59
answered Jun 30 '16 at 5:53
jimmij
29.3k867101
29.3k867101
add a comment |Â
add a comment |Â
up vote
0
down vote
Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.
case $line in
"#"*) echo no
esac
The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.
If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in
case $line in
"#"*) echo no ;;
*) echo yes
esac
... and the code for a pattern may be empty:
case $line in
"#"*) ;;
*) echo yes
esac
The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:
if [[ $line != "#"* ]]; then
echo yes
else
echo no
fi
In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:
if ! [[ $line =~ ^# ]]; then
echo yes
else
echo no
fi
or
if [[ $line =~ ^[^#] ]]; then
echo yes
else
echo no
fi
If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:
awk '/^[^#]/ print yes ' <inputfile
Related:
- Why is using a shell loop to process text considered bad practice?
add a comment |Â
up vote
0
down vote
Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.
case $line in
"#"*) echo no
esac
The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.
If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in
case $line in
"#"*) echo no ;;
*) echo yes
esac
... and the code for a pattern may be empty:
case $line in
"#"*) ;;
*) echo yes
esac
The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:
if [[ $line != "#"* ]]; then
echo yes
else
echo no
fi
In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:
if ! [[ $line =~ ^# ]]; then
echo yes
else
echo no
fi
or
if [[ $line =~ ^[^#] ]]; then
echo yes
else
echo no
fi
If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:
awk '/^[^#]/ print yes ' <inputfile
Related:
- Why is using a shell loop to process text considered bad practice?
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.
case $line in
"#"*) echo no
esac
The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.
If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in
case $line in
"#"*) echo no ;;
*) echo yes
esac
... and the code for a pattern may be empty:
case $line in
"#"*) ;;
*) echo yes
esac
The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:
if [[ $line != "#"* ]]; then
echo yes
else
echo no
fi
In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:
if ! [[ $line =~ ^# ]]; then
echo yes
else
echo no
fi
or
if [[ $line =~ ^[^#] ]]; then
echo yes
else
echo no
fi
If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:
awk '/^[^#]/ print yes ' <inputfile
Related:
- Why is using a shell loop to process text considered bad practice?
Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.
case $line in
"#"*) echo no
esac
The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.
If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in
case $line in
"#"*) echo no ;;
*) echo yes
esac
... and the code for a pattern may be empty:
case $line in
"#"*) ;;
*) echo yes
esac
The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:
if [[ $line != "#"* ]]; then
echo yes
else
echo no
fi
In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:
if ! [[ $line =~ ^# ]]; then
echo yes
else
echo no
fi
or
if [[ $line =~ ^[^#] ]]; then
echo yes
else
echo no
fi
If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:
awk '/^[^#]/ print yes ' <inputfile
Related:
- Why is using a shell loop to process text considered bad practice?
edited Aug 31 at 7:02
answered Aug 31 at 6:54
Kusalananda
107k14209331
107k14209331
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f293016%2fhow-to-check-not-starts-with-condition-in-if-statement%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password