I am tired of creating a file with nano, saving it and then making it executable. Is there a command that makes it in one step?
I am tired of creating a file with nano, saving it and then making it executable. Is there a command that makes it in one step?
14 Comments
cyborganism@lemmy.ca · 70 pts · 2y
You mean like
touch file && chmod +x file?MrAlternateTape@lemm.ee · 14 pts · 2y
Wrap it up folks, we're done here.
CameronDev@programming.dev · 35 pts · 2y
Write an alias/function to do it and add to your bashrc.
psmgx@lemmy.world · 0 pts · 2y
This is the way.
NegativeLookBehind@lemmy.world · 16 pts · 2y
kureta@lemmy.ml · 6 pts · 2y
touch file && chmod +x fileis good but this here is the one true command for the purpose.hapidjus@mastodon.social · 1 pts · 2y
kureta@lemmy.ml · 2 pts · 2y
that's what I was trying to say.
2xsaiko@discuss.tchncs.de · 2 pts · 2y
install -m755 /dev/null targetwas the first thing I thought of. I would never use this but it is a single command.NegativeLookBehind@lemmy.world · 1 pts · 2y
2xsaiko@discuss.tchncs.de · 1 pts · 2y
I'm going to write (at least part of) the script first anyway, and then I can just use chmod +x after the file is saved which is shorter.
kayaven@lemmy.world · 12 pts · 2y
You could define a function that takes a parameter, which touches a file with the parameters value, chmods it and then opens it with nano?
Then you could type
create_exec file.shand it would do the rest for you.sneakyninjapants@sh.itjust.works · 11 pts · 2y
Here's one I have saved in my shell aliases.
Admittedly much more complicated than necessary, but it's pretty full featured. first line constructs a filename for the new script from a generated 10 character random hash and prepends "nscript" and a user provided name.
The second line writes out the shebang and a few oft used bash flags, makes the file executable and opens in in my editor (Helix in my case).
The third line is just a shortened alias for the function.
eruchitanda@lemmy.world · 7 pts · 2y
Use
&&to use multiple commands one after the other, don't use;.eruchitanda@lemmy.world · 18 pts · 2y
-
&&means execute if the command before ended successfully-
||means execute if the commnad before failed-
;just means execute the command - no matter if succeeded or failedArcaneSlime@lemmy.dbzer0.com · 1 pts · 2y
My dude, thanks for this. I've been using && for a long time now but never knew the rest, I'm still pretty new to linux comparatively.
eruchitanda@lemmy.world · 2 pts · 2y
bjoern_tantau@swg-empire.de · 3 pts · 2y
You could append the chmod command with && but that's probably not what you wanted.