bash: Bad Substitution
up vote
85
down vote
favorite
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
This bash script gives me Bad substitution error on Ubuntu. Any help will be highly appreciated.
string bash ubuntu substitution
|
show 2 more comments
up vote
85
down vote
favorite
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
This bash script gives me Bad substitution error on Ubuntu. Any help will be highly appreciated.
string bash ubuntu substitution
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
Mmmm strange. What if you usecut
?cut -d_ -f1,2 <<< "$jobname"
andcut -d_ -f3 <<< "$jobname"
make it
– fedorqui
Dec 16 '13 at 16:06
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
1
@bludger you are right, I see that if you dosh script.sh
it gets a "Bad substitution" error.
– fedorqui
Dec 16 '13 at 16:18
|
show 2 more comments
up vote
85
down vote
favorite
up vote
85
down vote
favorite
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
This bash script gives me Bad substitution error on Ubuntu. Any help will be highly appreciated.
string bash ubuntu substitution
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
This bash script gives me Bad substitution error on Ubuntu. Any help will be highly appreciated.
string bash ubuntu substitution
string bash ubuntu substitution
edited Oct 8 at 14:50
asked Dec 16 '13 at 16:01
Arindam Choudhury
6221716
6221716
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
Mmmm strange. What if you usecut
?cut -d_ -f1,2 <<< "$jobname"
andcut -d_ -f3 <<< "$jobname"
make it
– fedorqui
Dec 16 '13 at 16:06
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
1
@bludger you are right, I see that if you dosh script.sh
it gets a "Bad substitution" error.
– fedorqui
Dec 16 '13 at 16:18
|
show 2 more comments
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
Mmmm strange. What if you usecut
?cut -d_ -f1,2 <<< "$jobname"
andcut -d_ -f3 <<< "$jobname"
make it
– fedorqui
Dec 16 '13 at 16:06
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
1
@bludger you are right, I see that if you dosh script.sh
it gets a "Bad substitution" error.
– fedorqui
Dec 16 '13 at 16:18
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
Mmmm strange. What if you use
cut
? cut -d_ -f1,2 <<< "$jobname"
and cut -d_ -f3 <<< "$jobname"
make it– fedorqui
Dec 16 '13 at 16:06
Mmmm strange. What if you use
cut
? cut -d_ -f1,2 <<< "$jobname"
and cut -d_ -f3 <<< "$jobname"
make it– fedorqui
Dec 16 '13 at 16:06
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
1
1
@bludger you are right, I see that if you do
sh script.sh
it gets a "Bad substitution" error.– fedorqui
Dec 16 '13 at 16:18
@bludger you are right, I see that if you do
sh script.sh
it gets a "Bad substitution" error.– fedorqui
Dec 16 '13 at 16:18
|
show 2 more comments
7 Answers
7
active
oldest
votes
up vote
136
down vote
accepted
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
1
He is using/bin/bash
so your answer does not fit?! Where do you read he's using/bin/sh
orsh script.sh
?
– DanFromGermany
Dec 1 '15 at 10:31
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
I dont need to downvote. I have the same error messagebad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.
– DanFromGermany
Dec 1 '15 at 12:47
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
Change#!/bin/sh
to#!/bin/bash
work to me.
– Evi Song
Oct 23 at 6:18
add a comment |
up vote
43
down vote
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash
4
I used#!bin/bash
andsh script.sh
, it still gave me the error message. Then./script.sh
works.
– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding#!/bin/bash
will also fix the Bad substitution.
– Jamie
Aug 20 '16 at 9:56
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
@whyisyoung the#!
line is used only when you execute your script directly. If you usesh script.sh
the line is completely ignored.
– bfontaine
Oct 4 at 14:21
add a comment |
up vote
18
down vote
Your script syntax is valid bash and good.
Possible causes for the failure:
Your
bash
is not really bash butksh
or some other shell which doesn't understand bash's parameter substitution. Because your script looks fine and works with bash.
Dols -l /bin/bash
and check it's really bash and not sym-linked to some other shell.If you do have bash on your system, then you may be executing your script the wrong way like:
ksh script.sh
orsh script.sh
(and your default shell is not bash). Since you have proper shebang, if you have bash./script.sh
orbash ./script.sh
should be fine.
7
I'd be surprised if/bin/bash
(not/bin/sh
) were ever linked to a different shell.
– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
add a comment |
up vote
11
down vote
For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh}
instead of the correct $(which sh)
add a comment |
up vote
6
down vote
Try running the script explicitly using bash command rather than just executing it as executable.
3
Good one. It would be helpful to add some sample output to make it more clear, by usingsh script
andbash script
... my suggestion :)
– fedorqui
Dec 16 '13 at 16:23
add a comment |
up vote
1
down vote
Also, make sure you don't have an empty string for the first line of your script.
i.e. make sure #!/bin/bash is the very first line of your script.
add a comment |
up vote
0
down vote
Both - bash or dash - work, but the syntax needs to be:
FILENAME=/my/complex/path/name.ext
NEWNAME=${FILENAME%ext}new
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
add a comment |
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
136
down vote
accepted
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
1
He is using/bin/bash
so your answer does not fit?! Where do you read he's using/bin/sh
orsh script.sh
?
– DanFromGermany
Dec 1 '15 at 10:31
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
I dont need to downvote. I have the same error messagebad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.
– DanFromGermany
Dec 1 '15 at 12:47
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
Change#!/bin/sh
to#!/bin/bash
work to me.
– Evi Song
Oct 23 at 6:18
add a comment |
up vote
136
down vote
accepted
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
1
He is using/bin/bash
so your answer does not fit?! Where do you read he's using/bin/sh
orsh script.sh
?
– DanFromGermany
Dec 1 '15 at 10:31
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
I dont need to downvote. I have the same error messagebad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.
– DanFromGermany
Dec 1 '15 at 12:47
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
Change#!/bin/sh
to#!/bin/bash
work to me.
– Evi Song
Oct 23 at 6:18
add a comment |
up vote
136
down vote
accepted
up vote
136
down vote
accepted
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
answered Dec 16 '13 at 16:44
Vanni Totaro
2,92321632
2,92321632
1
He is using/bin/bash
so your answer does not fit?! Where do you read he's using/bin/sh
orsh script.sh
?
– DanFromGermany
Dec 1 '15 at 10:31
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
I dont need to downvote. I have the same error messagebad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.
– DanFromGermany
Dec 1 '15 at 12:47
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
Change#!/bin/sh
to#!/bin/bash
work to me.
– Evi Song
Oct 23 at 6:18
add a comment |
1
He is using/bin/bash
so your answer does not fit?! Where do you read he's using/bin/sh
orsh script.sh
?
– DanFromGermany
Dec 1 '15 at 10:31
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
I dont need to downvote. I have the same error messagebad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.
– DanFromGermany
Dec 1 '15 at 12:47
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
Change#!/bin/sh
to#!/bin/bash
work to me.
– Evi Song
Oct 23 at 6:18
1
1
He is using
/bin/bash
so your answer does not fit?! Where do you read he's using /bin/sh
or sh script.sh
?– DanFromGermany
Dec 1 '15 at 10:31
He is using
/bin/bash
so your answer does not fit?! Where do you read he's using /bin/sh
or sh script.sh
?– DanFromGermany
Dec 1 '15 at 10:31
2
2
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
@DanFromGermany because that's the only reason for that error, i.e. he's running the script in a way that doesn't consider the hashbang, and that bash syntax is not supported by some other shell (probably dash). Questions don't always contain all the needed details, and we must join the dots... anyway feel free to downvote my answer.
– Vanni Totaro
Dec 1 '15 at 11:10
1
1
I dont need to downvote. I have the same error message
bad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.– DanFromGermany
Dec 1 '15 at 12:47
I dont need to downvote. I have the same error message
bad substitution
and I'm just trying to gather information but this question doesn't help because it has too few information.– DanFromGermany
Dec 1 '15 at 12:47
2
2
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
@DanFromGermany you could try posting your own question, maybe it's not exactly the same problem.
– Vanni Totaro
Dec 1 '15 at 13:27
1
1
Change
#!/bin/sh
to #!/bin/bash
work to me.– Evi Song
Oct 23 at 6:18
Change
#!/bin/sh
to #!/bin/bash
work to me.– Evi Song
Oct 23 at 6:18
add a comment |
up vote
43
down vote
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash
4
I used#!bin/bash
andsh script.sh
, it still gave me the error message. Then./script.sh
works.
– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding#!/bin/bash
will also fix the Bad substitution.
– Jamie
Aug 20 '16 at 9:56
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
@whyisyoung the#!
line is used only when you execute your script directly. If you usesh script.sh
the line is completely ignored.
– bfontaine
Oct 4 at 14:21
add a comment |
up vote
43
down vote
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash
4
I used#!bin/bash
andsh script.sh
, it still gave me the error message. Then./script.sh
works.
– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding#!/bin/bash
will also fix the Bad substitution.
– Jamie
Aug 20 '16 at 9:56
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
@whyisyoung the#!
line is used only when you execute your script directly. If you usesh script.sh
the line is completely ignored.
– bfontaine
Oct 4 at 14:21
add a comment |
up vote
43
down vote
up vote
43
down vote
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash
edited Apr 24 '14 at 19:39
ZeMoon
15.3k34281
15.3k34281
answered Apr 24 '14 at 19:02
Guest
43942
43942
4
I used#!bin/bash
andsh script.sh
, it still gave me the error message. Then./script.sh
works.
– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding#!/bin/bash
will also fix the Bad substitution.
– Jamie
Aug 20 '16 at 9:56
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
@whyisyoung the#!
line is used only when you execute your script directly. If you usesh script.sh
the line is completely ignored.
– bfontaine
Oct 4 at 14:21
add a comment |
4
I used#!bin/bash
andsh script.sh
, it still gave me the error message. Then./script.sh
works.
– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding#!/bin/bash
will also fix the Bad substitution.
– Jamie
Aug 20 '16 at 9:56
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
@whyisyoung the#!
line is used only when you execute your script directly. If you usesh script.sh
the line is completely ignored.
– bfontaine
Oct 4 at 14:21
4
4
I used
#!bin/bash
and sh script.sh
, it still gave me the error message. Then ./script.sh
works.– whyisyoung
Apr 9 '15 at 2:13
I used
#!bin/bash
and sh script.sh
, it still gave me the error message. Then ./script.sh
works.– whyisyoung
Apr 9 '15 at 2:13
If your file is missing a shebang at the top adding
#!/bin/bash
will also fix the Bad substitution.– Jamie
Aug 20 '16 at 9:56
If your file is missing a shebang at the top adding
#!/bin/bash
will also fix the Bad substitution.– Jamie
Aug 20 '16 at 9:56
1
1
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
@whyisyoung your variable could be having a dot (.) in its name. It gives bad subst. error.
– user13107
Sep 7 '16 at 1:13
1
1
@whyisyoung the
#!
line is used only when you execute your script directly. If you use sh script.sh
the line is completely ignored.– bfontaine
Oct 4 at 14:21
@whyisyoung the
#!
line is used only when you execute your script directly. If you use sh script.sh
the line is completely ignored.– bfontaine
Oct 4 at 14:21
add a comment |
up vote
18
down vote
Your script syntax is valid bash and good.
Possible causes for the failure:
Your
bash
is not really bash butksh
or some other shell which doesn't understand bash's parameter substitution. Because your script looks fine and works with bash.
Dols -l /bin/bash
and check it's really bash and not sym-linked to some other shell.If you do have bash on your system, then you may be executing your script the wrong way like:
ksh script.sh
orsh script.sh
(and your default shell is not bash). Since you have proper shebang, if you have bash./script.sh
orbash ./script.sh
should be fine.
7
I'd be surprised if/bin/bash
(not/bin/sh
) were ever linked to a different shell.
– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
add a comment |
up vote
18
down vote
Your script syntax is valid bash and good.
Possible causes for the failure:
Your
bash
is not really bash butksh
or some other shell which doesn't understand bash's parameter substitution. Because your script looks fine and works with bash.
Dols -l /bin/bash
and check it's really bash and not sym-linked to some other shell.If you do have bash on your system, then you may be executing your script the wrong way like:
ksh script.sh
orsh script.sh
(and your default shell is not bash). Since you have proper shebang, if you have bash./script.sh
orbash ./script.sh
should be fine.
7
I'd be surprised if/bin/bash
(not/bin/sh
) were ever linked to a different shell.
– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
add a comment |
up vote
18
down vote
up vote
18
down vote
Your script syntax is valid bash and good.
Possible causes for the failure:
Your
bash
is not really bash butksh
or some other shell which doesn't understand bash's parameter substitution. Because your script looks fine and works with bash.
Dols -l /bin/bash
and check it's really bash and not sym-linked to some other shell.If you do have bash on your system, then you may be executing your script the wrong way like:
ksh script.sh
orsh script.sh
(and your default shell is not bash). Since you have proper shebang, if you have bash./script.sh
orbash ./script.sh
should be fine.
Your script syntax is valid bash and good.
Possible causes for the failure:
Your
bash
is not really bash butksh
or some other shell which doesn't understand bash's parameter substitution. Because your script looks fine and works with bash.
Dols -l /bin/bash
and check it's really bash and not sym-linked to some other shell.If you do have bash on your system, then you may be executing your script the wrong way like:
ksh script.sh
orsh script.sh
(and your default shell is not bash). Since you have proper shebang, if you have bash./script.sh
orbash ./script.sh
should be fine.
answered Dec 16 '13 at 16:35
P.P.
74.3k11101152
74.3k11101152
7
I'd be surprised if/bin/bash
(not/bin/sh
) were ever linked to a different shell.
– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
add a comment |
7
I'd be surprised if/bin/bash
(not/bin/sh
) were ever linked to a different shell.
– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
7
7
I'd be surprised if
/bin/bash
(not /bin/sh
) were ever linked to a different shell.– chepner
Dec 16 '13 at 17:46
I'd be surprised if
/bin/bash
(not /bin/sh
) were ever linked to a different shell.– chepner
Dec 16 '13 at 17:46
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
ksh is actually where most of bash's syntax extensions originated from; it certainly has the specific parameter expansion syntax in question. I wouldn't tend to suggest calling it out as a shell unlikely to be capable.
– Charles Duffy
Apr 28 '17 at 23:13
add a comment |
up vote
11
down vote
For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh}
instead of the correct $(which sh)
add a comment |
up vote
11
down vote
For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh}
instead of the correct $(which sh)
add a comment |
up vote
11
down vote
up vote
11
down vote
For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh}
instead of the correct $(which sh)
For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh}
instead of the correct $(which sh)
answered Aug 17 '16 at 9:33
Nacho Coloma
4,54312940
4,54312940
add a comment |
add a comment |
up vote
6
down vote
Try running the script explicitly using bash command rather than just executing it as executable.
3
Good one. It would be helpful to add some sample output to make it more clear, by usingsh script
andbash script
... my suggestion :)
– fedorqui
Dec 16 '13 at 16:23
add a comment |
up vote
6
down vote
Try running the script explicitly using bash command rather than just executing it as executable.
3
Good one. It would be helpful to add some sample output to make it more clear, by usingsh script
andbash script
... my suggestion :)
– fedorqui
Dec 16 '13 at 16:23
add a comment |
up vote
6
down vote
up vote
6
down vote
Try running the script explicitly using bash command rather than just executing it as executable.
Try running the script explicitly using bash command rather than just executing it as executable.
answered Dec 16 '13 at 16:18
Pale Blue Dot
3,58076095
3,58076095
3
Good one. It would be helpful to add some sample output to make it more clear, by usingsh script
andbash script
... my suggestion :)
– fedorqui
Dec 16 '13 at 16:23
add a comment |
3
Good one. It would be helpful to add some sample output to make it more clear, by usingsh script
andbash script
... my suggestion :)
– fedorqui
Dec 16 '13 at 16:23
3
3
Good one. It would be helpful to add some sample output to make it more clear, by using
sh script
and bash script
... my suggestion :)– fedorqui
Dec 16 '13 at 16:23
Good one. It would be helpful to add some sample output to make it more clear, by using
sh script
and bash script
... my suggestion :)– fedorqui
Dec 16 '13 at 16:23
add a comment |
up vote
1
down vote
Also, make sure you don't have an empty string for the first line of your script.
i.e. make sure #!/bin/bash is the very first line of your script.
add a comment |
up vote
1
down vote
Also, make sure you don't have an empty string for the first line of your script.
i.e. make sure #!/bin/bash is the very first line of your script.
add a comment |
up vote
1
down vote
up vote
1
down vote
Also, make sure you don't have an empty string for the first line of your script.
i.e. make sure #!/bin/bash is the very first line of your script.
Also, make sure you don't have an empty string for the first line of your script.
i.e. make sure #!/bin/bash is the very first line of your script.
answered Apr 5 '16 at 18:23
wizurd
2,13031940
2,13031940
add a comment |
add a comment |
up vote
0
down vote
Both - bash or dash - work, but the syntax needs to be:
FILENAME=/my/complex/path/name.ext
NEWNAME=${FILENAME%ext}new
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
add a comment |
up vote
0
down vote
Both - bash or dash - work, but the syntax needs to be:
FILENAME=/my/complex/path/name.ext
NEWNAME=${FILENAME%ext}new
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
add a comment |
up vote
0
down vote
up vote
0
down vote
Both - bash or dash - work, but the syntax needs to be:
FILENAME=/my/complex/path/name.ext
NEWNAME=${FILENAME%ext}new
Both - bash or dash - work, but the syntax needs to be:
FILENAME=/my/complex/path/name.ext
NEWNAME=${FILENAME%ext}new
answered Mar 10 '16 at 10:03
Hagen
1
1
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
add a comment |
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
That's a completely different operation. Also, since the OP was following good practices by using lower-case variable names (see pubs.opengroup.org/onlinepubs/9699919799/basedefs/… -- uppercase names are used for variables with meaning to the OS or shell; lowercase names are reserved for application use), it behooves to do likewise.
– Charles Duffy
Apr 28 '17 at 23:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20615217%2fbash-bad-substitution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It is working fine to me. What are you trying to accomplish?
– fedorqui
Dec 16 '13 at 16:03
I am trying to divide the jobname into two: job_201312161447 and 0003. Its giving this error only when I am trying to run this on ubuntu.
– Arindam Choudhury
Dec 16 '13 at 16:04
Mmmm strange. What if you use
cut
?cut -d_ -f1,2 <<< "$jobname"
andcut -d_ -f3 <<< "$jobname"
make it– fedorqui
Dec 16 '13 at 16:06
thanks. but why jobname_pre=${jobname:0:16} gave error
– Arindam Choudhury
Dec 16 '13 at 16:15
1
@bludger you are right, I see that if you do
sh script.sh
it gets a "Bad substitution" error.– fedorqui
Dec 16 '13 at 16:18