Trying to compile a file and open it for edit if it fails or run it if it goes throughLooping through the content of a file in BashLooking for a bash script to run a program with different inputs on linux serverTransfer a file to remote machine(ubuntu) while running bash remotelyHow do I convert this bash loop to python?check if file is open with lsofHow does this perl one liner in the bash works?Bash - Compiling sleep loadableSimple bash scriptCreating self-executable node.js serverWriting to a file multiple times with Bash
How are mathematicians paid to do research?
How do we handle pauses in a dialogue?
What were the main German words for a prostitute before 1800?
Short story about Nobel Prize winning scientists that drop out when they realise they were incorrect
Why would non-kinetic weapons be used for orbital bombardment?
Why didn't Thanos kill all the Dwarves on Nidavellir?
Is a request to book a business flight ticket for a graduate student an unreasonable one?
Why does wrapping aluminium foil around my food help it keep warm, even though aluminium is a good conductor?
Can the Mage Hand cantrip be used to trip an enemy who is running away?
Is "I do not want you to go nowhere" a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?
Swapping "Good" and "Bad"
Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?
Why is the ladder of the LM always in the dark side of the LM?
Is it correct to join training and validation set before inferring on test-set?
How do native German speakers usually express skepticism (using even) about a premise?
Which star / galaxy is moving away from us the fastest?
Addressing unnecessary daily meetings with manager?
Was I subtly told to resign?
How can I truly shut down ssh server?
Print the last, middle and first character of your code
If your plane is out-of-control, why does military training instruct releasing the joystick to neutralize controls?
Misspelling my name on my mathematical publications
Is "De qui parles-tu" (for example) as formal as it is in English, or is it normal for the French to casually say that
Credit score and financing new car
Trying to compile a file and open it for edit if it fails or run it if it goes through
Looping through the content of a file in BashLooking for a bash script to run a program with different inputs on linux serverTransfer a file to remote machine(ubuntu) while running bash remotelyHow do I convert this bash loop to python?check if file is open with lsofHow does this perl one liner in the bash works?Bash - Compiling sleep loadableSimple bash scriptCreating self-executable node.js serverWriting to a file multiple times with Bash
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
So I have written this line of Bash
rustc hello.rs && ./hello || ( exit_on_error sleep 10s ; vi hello.rs )
The goal is that I compile the file. If compilation is successful it should run the script. If not it should give me 10 seconds to read the error before opening the file for edit again.
I have been having trouble getting the sleep and the edit to happen sequentially and only when the compilation fails. I cant figure out what type of bracket to use. In this version if compilation fails it immediately opens the file for edit.
How can I achieve the desired result here?
bash
add a comment |
So I have written this line of Bash
rustc hello.rs && ./hello || ( exit_on_error sleep 10s ; vi hello.rs )
The goal is that I compile the file. If compilation is successful it should run the script. If not it should give me 10 seconds to read the error before opening the file for edit again.
I have been having trouble getting the sleep and the edit to happen sequentially and only when the compilation fails. I cant figure out what type of bracket to use. In this version if compilation fails it immediately opens the file for edit.
How can I achieve the desired result here?
bash
Regarding "I cant figure out what type of bracket to use", the( )
you're using creates a subshell, which is probably not what you want.
– dimo414
Apr 7 at 23:30
add a comment |
So I have written this line of Bash
rustc hello.rs && ./hello || ( exit_on_error sleep 10s ; vi hello.rs )
The goal is that I compile the file. If compilation is successful it should run the script. If not it should give me 10 seconds to read the error before opening the file for edit again.
I have been having trouble getting the sleep and the edit to happen sequentially and only when the compilation fails. I cant figure out what type of bracket to use. In this version if compilation fails it immediately opens the file for edit.
How can I achieve the desired result here?
bash
So I have written this line of Bash
rustc hello.rs && ./hello || ( exit_on_error sleep 10s ; vi hello.rs )
The goal is that I compile the file. If compilation is successful it should run the script. If not it should give me 10 seconds to read the error before opening the file for edit again.
I have been having trouble getting the sleep and the edit to happen sequentially and only when the compilation fails. I cant figure out what type of bracket to use. In this version if compilation fails it immediately opens the file for edit.
How can I achieve the desired result here?
bash
bash
asked Mar 26 at 1:28
CalebKCalebK
758 bronze badges
758 bronze badges
Regarding "I cant figure out what type of bracket to use", the( )
you're using creates a subshell, which is probably not what you want.
– dimo414
Apr 7 at 23:30
add a comment |
Regarding "I cant figure out what type of bracket to use", the( )
you're using creates a subshell, which is probably not what you want.
– dimo414
Apr 7 at 23:30
Regarding "I cant figure out what type of bracket to use", the
( )
you're using creates a subshell, which is probably not what you want.
is simply a grouping operator. See The Bash Manual.– dimo414
Apr 7 at 23:30
Regarding "I cant figure out what type of bracket to use", the
( )
you're using creates a subshell, which is probably not what you want.
is simply a grouping operator. See The Bash Manual.– dimo414
Apr 7 at 23:30
add a comment |
1 Answer
1
active
oldest
votes
I wouldn't waste time trying to understand the interactions of multiple sequential &&
and ||
operations (especially not in a mixture — all the same is OK). I'd just write it cleanly:
if rustc hello.rs
then ./hello
else sleep 10s; vi hello.rs
fi
which can be flattened onto a single line with:
if rustc hello.rs; then ./hello; else sleep 10s; vi hello.rs; fi
But I'd make it into a script which takes the file name(s) as arguments and processes them, etc, with environment variables to adjust the compiler and options too.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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%2fstackoverflow.com%2fquestions%2f55348617%2ftrying-to-compile-a-file-and-open-it-for-edit-if-it-fails-or-run-it-if-it-goes-t%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
I wouldn't waste time trying to understand the interactions of multiple sequential &&
and ||
operations (especially not in a mixture — all the same is OK). I'd just write it cleanly:
if rustc hello.rs
then ./hello
else sleep 10s; vi hello.rs
fi
which can be flattened onto a single line with:
if rustc hello.rs; then ./hello; else sleep 10s; vi hello.rs; fi
But I'd make it into a script which takes the file name(s) as arguments and processes them, etc, with environment variables to adjust the compiler and options too.
add a comment |
I wouldn't waste time trying to understand the interactions of multiple sequential &&
and ||
operations (especially not in a mixture — all the same is OK). I'd just write it cleanly:
if rustc hello.rs
then ./hello
else sleep 10s; vi hello.rs
fi
which can be flattened onto a single line with:
if rustc hello.rs; then ./hello; else sleep 10s; vi hello.rs; fi
But I'd make it into a script which takes the file name(s) as arguments and processes them, etc, with environment variables to adjust the compiler and options too.
add a comment |
I wouldn't waste time trying to understand the interactions of multiple sequential &&
and ||
operations (especially not in a mixture — all the same is OK). I'd just write it cleanly:
if rustc hello.rs
then ./hello
else sleep 10s; vi hello.rs
fi
which can be flattened onto a single line with:
if rustc hello.rs; then ./hello; else sleep 10s; vi hello.rs; fi
But I'd make it into a script which takes the file name(s) as arguments and processes them, etc, with environment variables to adjust the compiler and options too.
I wouldn't waste time trying to understand the interactions of multiple sequential &&
and ||
operations (especially not in a mixture — all the same is OK). I'd just write it cleanly:
if rustc hello.rs
then ./hello
else sleep 10s; vi hello.rs
fi
which can be flattened onto a single line with:
if rustc hello.rs; then ./hello; else sleep 10s; vi hello.rs; fi
But I'd make it into a script which takes the file name(s) as arguments and processes them, etc, with environment variables to adjust the compiler and options too.
answered Mar 26 at 1:50
Jonathan LefflerJonathan Leffler
586k96 gold badges706 silver badges1056 bronze badges
586k96 gold badges706 silver badges1056 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
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%2f55348617%2ftrying-to-compile-a-file-and-open-it-for-edit-if-it-fails-or-run-it-if-it-goes-t%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
Regarding "I cant figure out what type of bracket to use", the
( )
you're using creates a subshell, which is probably not what you want.– dimo414
Apr 7 at 23:30