Error when running ((x++)) as rootWhich shell interpreter runs a script with no shebang?How to hinder root from running a scriptUnable to delete file, even when running as rootError when running X11 application as rootNginx Static Build - Run as root with a non-root userBash root to user. Best in same or separate script?Python imports working for root, but not specific userIs it possible to retain the union of user privileges and root privileges when using sudo?How to stop a script from running if it's not root (and echo “Not running as root! Exiting…”)How to run jhbuild as rootWhy different command scripts are used for the same command when run as a normal user and when run as a root user?
Of strange atmospheres - the survivable but unbreathable
Why does splatting create a tuple on the rhs but a list on the lhs?
How to determine if a hyphen (-) exists inside a column
Are there any German nonsense poems (Jabberwocky)?
Does an eye for an eye mean monetary compensation?
Burned out due to current job, Can I take a week of vacation between jobs?
Why does FOO=bar; export the variable into my environment
Need to read my home electrical Meter
Navigating a quick return to previous employer
How to melt snow without fire or using body heat?
Which European Languages are not Indo-European?
Where is Jon going?
Expected maximum number of unpaired socks
Why did other houses not demand this?
How does the Earth's center produce heat?
How to politely tell someone they did not hit reply all in email?
Is "vegetable base" a common term in English?
Why does Bran want to find Drogon?
What are nvme namespaces? How do they work?
What is the use case for non-breathable waterproof pants?
What were the Ethiopians doing in Xerxes' army?
First Program Tic-Tac-Toe
How to keep consistency across the application architecture as a team grows?
Why isn't 'chemically-strengthened glass' made with potassium carbonate? To begin with?
Error when running ((x++)) as root
Which shell interpreter runs a script with no shebang?How to hinder root from running a scriptUnable to delete file, even when running as rootError when running X11 application as rootNginx Static Build - Run as root with a non-root userBash root to user. Best in same or separate script?Python imports working for root, but not specific userIs it possible to retain the union of user privileges and root privileges when using sudo?How to stop a script from running if it's not root (and echo “Not running as root! Exiting…”)How to run jhbuild as rootWhy different command scripts are used for the same command when run as a normal user and when run as a root user?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I make bash script temp.sh with the following content:
age=0;
((age++));
When I run it as a normal user, it runs fine.
But when i run it as root I get error:
./temp.sh: 4: ./temp.sh: age++: not found
Why is that?
root
add a comment |
I make bash script temp.sh with the following content:
age=0;
((age++));
When I run it as a normal user, it runs fine.
But when i run it as root I get error:
./temp.sh: 4: ./temp.sh: age++: not found
Why is that?
root
Are you using the same shell and settings for both users ? What's the output ofecho $SHELL
as non-root and as root ?
– Httqm
May 16 at 15:22
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be your root shell.
– Isaac
May 16 at 19:21
add a comment |
I make bash script temp.sh with the following content:
age=0;
((age++));
When I run it as a normal user, it runs fine.
But when i run it as root I get error:
./temp.sh: 4: ./temp.sh: age++: not found
Why is that?
root
I make bash script temp.sh with the following content:
age=0;
((age++));
When I run it as a normal user, it runs fine.
But when i run it as root I get error:
./temp.sh: 4: ./temp.sh: age++: not found
Why is that?
root
root
edited May 16 at 22:56
Hermann Ingjaldsson
asked May 16 at 15:18
Hermann IngjaldssonHermann Ingjaldsson
81041630
81041630
Are you using the same shell and settings for both users ? What's the output ofecho $SHELL
as non-root and as root ?
– Httqm
May 16 at 15:22
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be your root shell.
– Isaac
May 16 at 19:21
add a comment |
Are you using the same shell and settings for both users ? What's the output ofecho $SHELL
as non-root and as root ?
– Httqm
May 16 at 15:22
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be your root shell.
– Isaac
May 16 at 19:21
Are you using the same shell and settings for both users ? What's the output of
echo $SHELL
as non-root and as root ?– Httqm
May 16 at 15:22
Are you using the same shell and settings for both users ? What's the output of
echo $SHELL
as non-root and as root ?– Httqm
May 16 at 15:22
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
The exact output of
./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as ./temp.sh
. That seems to be your root shell.– Isaac
May 16 at 19:21
The exact output of
./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as ./temp.sh
. That seems to be your root shell.– Isaac
May 16 at 19:21
add a comment |
2 Answers
2
active
oldest
votes
In the absence of a hashbang, /bin/sh
is likely being used. Some POSIX shells do support the ++
and --
operators, and ((...))
for arithmetic evaluations, but are not required to.
Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++))
as the age++
command being run inside two nested sub-shells.
When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...))
.
Related: Which shell interpreter runs a script with no shebang?
To fix this you can add a hashbang to your script:
#!/bin/bash
age=0
((age++))
Note: You do not need to terminate lines with ;
in bash/shell.
To make your script portable to all POSIX shells you can use the following syntax:
age=$((age + 1))
age=$((age += 1))
4
Or use the standardsh
syntax:age=$((age + 1))
, or: "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be the root shell.
– Isaac
May 16 at 19:19
add a comment |
Another old time answer (or highly multiple platform compatible) is:
age=`expr $age + 1`
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2funix.stackexchange.com%2fquestions%2f519310%2ferror-when-running-x-as-root%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the absence of a hashbang, /bin/sh
is likely being used. Some POSIX shells do support the ++
and --
operators, and ((...))
for arithmetic evaluations, but are not required to.
Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++))
as the age++
command being run inside two nested sub-shells.
When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...))
.
Related: Which shell interpreter runs a script with no shebang?
To fix this you can add a hashbang to your script:
#!/bin/bash
age=0
((age++))
Note: You do not need to terminate lines with ;
in bash/shell.
To make your script portable to all POSIX shells you can use the following syntax:
age=$((age + 1))
age=$((age += 1))
4
Or use the standardsh
syntax:age=$((age + 1))
, or: "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be the root shell.
– Isaac
May 16 at 19:19
add a comment |
In the absence of a hashbang, /bin/sh
is likely being used. Some POSIX shells do support the ++
and --
operators, and ((...))
for arithmetic evaluations, but are not required to.
Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++))
as the age++
command being run inside two nested sub-shells.
When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...))
.
Related: Which shell interpreter runs a script with no shebang?
To fix this you can add a hashbang to your script:
#!/bin/bash
age=0
((age++))
Note: You do not need to terminate lines with ;
in bash/shell.
To make your script portable to all POSIX shells you can use the following syntax:
age=$((age + 1))
age=$((age += 1))
4
Or use the standardsh
syntax:age=$((age + 1))
, or: "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be the root shell.
– Isaac
May 16 at 19:19
add a comment |
In the absence of a hashbang, /bin/sh
is likely being used. Some POSIX shells do support the ++
and --
operators, and ((...))
for arithmetic evaluations, but are not required to.
Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++))
as the age++
command being run inside two nested sub-shells.
When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...))
.
Related: Which shell interpreter runs a script with no shebang?
To fix this you can add a hashbang to your script:
#!/bin/bash
age=0
((age++))
Note: You do not need to terminate lines with ;
in bash/shell.
To make your script portable to all POSIX shells you can use the following syntax:
age=$((age + 1))
age=$((age += 1))
In the absence of a hashbang, /bin/sh
is likely being used. Some POSIX shells do support the ++
and --
operators, and ((...))
for arithmetic evaluations, but are not required to.
Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++))
as the age++
command being run inside two nested sub-shells.
When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...))
.
Related: Which shell interpreter runs a script with no shebang?
To fix this you can add a hashbang to your script:
#!/bin/bash
age=0
((age++))
Note: You do not need to terminate lines with ;
in bash/shell.
To make your script portable to all POSIX shells you can use the following syntax:
age=$((age + 1))
age=$((age += 1))
edited May 16 at 18:48
answered May 16 at 15:27
Jesse_bJesse_b
15.5k33776
15.5k33776
4
Or use the standardsh
syntax:age=$((age + 1))
, or: "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be the root shell.
– Isaac
May 16 at 19:19
add a comment |
4
Or use the standardsh
syntax:age=$((age + 1))
, or: "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
The exact output of./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be the root shell.
– Isaac
May 16 at 19:19
4
4
Or use the standard
sh
syntax: age=$((age + 1))
, or : "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
Or use the standard
sh
syntax: age=$((age + 1))
, or : "$((age += 1))"
– Stéphane Chazelas
May 16 at 18:46
2
2
The exact output of
./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as ./temp.sh
. That seems to be the root shell.– Isaac
May 16 at 19:19
The exact output of
./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as ./temp.sh
. That seems to be the root shell.– Isaac
May 16 at 19:19
add a comment |
Another old time answer (or highly multiple platform compatible) is:
age=`expr $age + 1`
add a comment |
Another old time answer (or highly multiple platform compatible) is:
age=`expr $age + 1`
add a comment |
Another old time answer (or highly multiple platform compatible) is:
age=`expr $age + 1`
Another old time answer (or highly multiple platform compatible) is:
age=`expr $age + 1`
answered May 16 at 23:20
mdpcmdpc
5,13621838
5,13621838
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f519310%2ferror-when-running-x-as-root%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
Are you using the same shell and settings for both users ? What's the output of
echo $SHELL
as non-root and as root ?– Httqm
May 16 at 15:22
its /bin/bash both as normal user and as root. But Jesse answered.
– Hermann Ingjaldsson
May 16 at 17:00
The exact output of
./temp.sh: 4: ./temp.sh: age++: not found
is generated by dash running an script called as./temp.sh
. That seems to be your root shell.– Isaac
May 16 at 19:21