Bash for loop does run foreverBash script, string not replaced correctly with escaped $ and &...
Giving a talk in my old university, how prominently should I tell students my salary?
How to get the first element while continue streaming?
Can I solder 12/2 Romex to extend wire 5 ft?
Formatting a table to look nice
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
Is there a frame of reference in which I was born before I was conceived?
Create chunks from an array
Lock enemy's y-axis when using Vector3.MoveTowards to follow the player
Rationale to prefer local variables over instance variables?
3.5% Interest Student Loan or use all of my savings on Tuition?
PTIJ: Is all laundering forbidden during the 9 days?
How does signal strength relate to bandwidth?
How can I conditionally format my HTML table?
Meaning of word ягоза
Deal the cards to the players
I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?
When was drinking water recognized as crucial in marathon running?
Being asked to review a paper in conference one has submitted to
Script that counts quarters, dimes, nickels, and pennies
Where is the fallacy here?
I can't die. Who am I?
Can a Trickery Domain cleric cast a spell through the Invoke Duplicity clone while inside a Forcecage?
Why won't the strings command stop?
Make me a metasequence
Bash for loop does run forever
Bash script, string not replaced correctly with escaped $ and & charactersweird behaviour with forever, bash, apache and phpBASH - run commands before and after loopWhile loop Bash script that outputs how many users use a certain shellLoop to execute multiple instructions in bash, which start from the top if one instruction failBatch file input issues on remote computerLast background process ID ($!) not working in sudo bash commandBash script that itself generates bash commandsHow do I make my backspace key functional in a bash script for Linux being accessed remotely from Windows?What am I doing wrong in this bash script?
Okay so i build a script to send me notifications after a certain amount of time.
Here's the part which doesn't work (will highlight important stuff later):
if [[ $choice == "-c" ]]
then
timer=$2
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
echo $timer
if [[ $5 == "-h" ]]
then
timer=$(( $2 * 3600 ))
fi
echo "Notification will be send in:" $timer "Second(s)"
for (( index = 0; index < $timer; index++ ))
do
sleep 1
done
notify-send -t $time $msg
fi
I call the script with
./scriptname <type> <time it should run> [message] [set the time to m/h]
The type doesn't matter here because it executes the correct if block.
The time it should run is how long it waits till the notification is send.
The set the time to m/h is a simple parameter. If i give nothing in here the time will be given in seconds (it always is but the user input isn't changed).
Okay so.
The $msg
variable contains the message which will get send.
$2
is the time input.
$choice
is not really important all it does is select the correct code to execute (and the programs comes in this if statement)
$5
contains either '-m' or '-h' (nothing is also an option) and then the $timer
variable gets increased by the following.
The problem is that if i want to have it in minutes (for what the "-m" stands). The programm will execute this statement:
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
With the echo $timer
i know that it worked but the problem i got is that the script doesn't stop running. It runs perfectly when i just execute it with the given input. (So the program doesn't go into any if statements for the $timer
variable.) But if i say that the time should be treated as minutes or hours (just tested with minutes) it doesn't work, or to be more correct it just doesn't override the $timer
variable
Does anybody know why?
linux command-line bash
add a comment |
Okay so i build a script to send me notifications after a certain amount of time.
Here's the part which doesn't work (will highlight important stuff later):
if [[ $choice == "-c" ]]
then
timer=$2
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
echo $timer
if [[ $5 == "-h" ]]
then
timer=$(( $2 * 3600 ))
fi
echo "Notification will be send in:" $timer "Second(s)"
for (( index = 0; index < $timer; index++ ))
do
sleep 1
done
notify-send -t $time $msg
fi
I call the script with
./scriptname <type> <time it should run> [message] [set the time to m/h]
The type doesn't matter here because it executes the correct if block.
The time it should run is how long it waits till the notification is send.
The set the time to m/h is a simple parameter. If i give nothing in here the time will be given in seconds (it always is but the user input isn't changed).
Okay so.
The $msg
variable contains the message which will get send.
$2
is the time input.
$choice
is not really important all it does is select the correct code to execute (and the programs comes in this if statement)
$5
contains either '-m' or '-h' (nothing is also an option) and then the $timer
variable gets increased by the following.
The problem is that if i want to have it in minutes (for what the "-m" stands). The programm will execute this statement:
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
With the echo $timer
i know that it worked but the problem i got is that the script doesn't stop running. It runs perfectly when i just execute it with the given input. (So the program doesn't go into any if statements for the $timer
variable.) But if i say that the time should be treated as minutes or hours (just tested with minutes) it doesn't work, or to be more correct it just doesn't override the $timer
variable
Does anybody know why?
linux command-line bash
1
Why don't you usesleep
to its full extent?sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...
– xenoid
yesterday
Is your script also namedsleep
?
– grawity
yesterday
Why are you looping instead of usingsleep $timer
? You can spawnsleep
once or $timer times.
– glenn jackman
yesterday
For using options, I'd recommendgetopts
-- then you're not forcing your users to enter options in a particular order.
– glenn jackman
yesterday
add a comment |
Okay so i build a script to send me notifications after a certain amount of time.
Here's the part which doesn't work (will highlight important stuff later):
if [[ $choice == "-c" ]]
then
timer=$2
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
echo $timer
if [[ $5 == "-h" ]]
then
timer=$(( $2 * 3600 ))
fi
echo "Notification will be send in:" $timer "Second(s)"
for (( index = 0; index < $timer; index++ ))
do
sleep 1
done
notify-send -t $time $msg
fi
I call the script with
./scriptname <type> <time it should run> [message] [set the time to m/h]
The type doesn't matter here because it executes the correct if block.
The time it should run is how long it waits till the notification is send.
The set the time to m/h is a simple parameter. If i give nothing in here the time will be given in seconds (it always is but the user input isn't changed).
Okay so.
The $msg
variable contains the message which will get send.
$2
is the time input.
$choice
is not really important all it does is select the correct code to execute (and the programs comes in this if statement)
$5
contains either '-m' or '-h' (nothing is also an option) and then the $timer
variable gets increased by the following.
The problem is that if i want to have it in minutes (for what the "-m" stands). The programm will execute this statement:
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
With the echo $timer
i know that it worked but the problem i got is that the script doesn't stop running. It runs perfectly when i just execute it with the given input. (So the program doesn't go into any if statements for the $timer
variable.) But if i say that the time should be treated as minutes or hours (just tested with minutes) it doesn't work, or to be more correct it just doesn't override the $timer
variable
Does anybody know why?
linux command-line bash
Okay so i build a script to send me notifications after a certain amount of time.
Here's the part which doesn't work (will highlight important stuff later):
if [[ $choice == "-c" ]]
then
timer=$2
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
echo $timer
if [[ $5 == "-h" ]]
then
timer=$(( $2 * 3600 ))
fi
echo "Notification will be send in:" $timer "Second(s)"
for (( index = 0; index < $timer; index++ ))
do
sleep 1
done
notify-send -t $time $msg
fi
I call the script with
./scriptname <type> <time it should run> [message] [set the time to m/h]
The type doesn't matter here because it executes the correct if block.
The time it should run is how long it waits till the notification is send.
The set the time to m/h is a simple parameter. If i give nothing in here the time will be given in seconds (it always is but the user input isn't changed).
Okay so.
The $msg
variable contains the message which will get send.
$2
is the time input.
$choice
is not really important all it does is select the correct code to execute (and the programs comes in this if statement)
$5
contains either '-m' or '-h' (nothing is also an option) and then the $timer
variable gets increased by the following.
The problem is that if i want to have it in minutes (for what the "-m" stands). The programm will execute this statement:
if [[ $5 == "-m" ]]
then
timer=$(( $2 * 60 ))
fi
With the echo $timer
i know that it worked but the problem i got is that the script doesn't stop running. It runs perfectly when i just execute it with the given input. (So the program doesn't go into any if statements for the $timer
variable.) But if i say that the time should be treated as minutes or hours (just tested with minutes) it doesn't work, or to be more correct it just doesn't override the $timer
variable
Does anybody know why?
linux command-line bash
linux command-line bash
edited yesterday
Stefan xyz
asked yesterday
Stefan xyzStefan xyz
63
63
1
Why don't you usesleep
to its full extent?sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...
– xenoid
yesterday
Is your script also namedsleep
?
– grawity
yesterday
Why are you looping instead of usingsleep $timer
? You can spawnsleep
once or $timer times.
– glenn jackman
yesterday
For using options, I'd recommendgetopts
-- then you're not forcing your users to enter options in a particular order.
– glenn jackman
yesterday
add a comment |
1
Why don't you usesleep
to its full extent?sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...
– xenoid
yesterday
Is your script also namedsleep
?
– grawity
yesterday
Why are you looping instead of usingsleep $timer
? You can spawnsleep
once or $timer times.
– glenn jackman
yesterday
For using options, I'd recommendgetopts
-- then you're not forcing your users to enter options in a particular order.
– glenn jackman
yesterday
1
1
Why don't you use
sleep
to its full extent? sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...– xenoid
yesterday
Why don't you use
sleep
to its full extent? sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...– xenoid
yesterday
Is your script also named
sleep
?– grawity
yesterday
Is your script also named
sleep
?– grawity
yesterday
Why are you looping instead of using
sleep $timer
? You can spawn sleep
once or $timer times.– glenn jackman
yesterday
Why are you looping instead of using
sleep $timer
? You can spawn sleep
once or $timer times.– glenn jackman
yesterday
For using options, I'd recommend
getopts
-- then you're not forcing your users to enter options in a particular order.– glenn jackman
yesterday
For using options, I'd recommend
getopts
-- then you're not forcing your users to enter options in a particular order.– glenn jackman
yesterday
add a comment |
1 Answer
1
active
oldest
votes
./scriptname <type> <time it should run> [message] [set the time to m/h]
[set the time to m/h]
is $4
. Your code tests against $5
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f1411603%2fbash-for-loop-does-run-forever%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
./scriptname <type> <time it should run> [message] [set the time to m/h]
[set the time to m/h]
is $4
. Your code tests against $5
.
add a comment |
./scriptname <type> <time it should run> [message] [set the time to m/h]
[set the time to m/h]
is $4
. Your code tests against $5
.
add a comment |
./scriptname <type> <time it should run> [message] [set the time to m/h]
[set the time to m/h]
is $4
. Your code tests against $5
.
./scriptname <type> <time it should run> [message] [set the time to m/h]
[set the time to m/h]
is $4
. Your code tests against $5
.
answered yesterday
Kamil MaciorowskiKamil Maciorowski
28k156184
28k156184
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1411603%2fbash-for-loop-does-run-forever%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
1
Why don't you use
sleep
to its full extent?sleep 5m
will sleep 5 minutes. No loops, no awkward parameter parsing...– xenoid
yesterday
Is your script also named
sleep
?– grawity
yesterday
Why are you looping instead of using
sleep $timer
? You can spawnsleep
once or $timer times.– glenn jackman
yesterday
For using options, I'd recommend
getopts
-- then you're not forcing your users to enter options in a particular order.– glenn jackman
yesterday