Llituro,
@Llituro@hexbear.net avatar

touch file && chmod +x file

eruchitanda,
@eruchitanda@lemmy.world avatar

Use && to use multiple commands one after the other, don’t use ;.

eruchitanda,
@eruchitanda@lemmy.world avatar
  • && 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 failed

ArcaneSlime,

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.

NegativeLookBehind,
@NegativeLookBehind@lemmy.world avatar

You want the install command.

install

At least, I think this will do it. I haven’t used it in a while.

kureta,

touch file && chmod +x file is good but this here is the one true command for the purpose.

2xsaiko,
@2xsaiko@discuss.tchncs.de avatar

install -m755 /dev/null target was the first thing I thought of. I would never use this but it is a single command.

NegativeLookBehind,
@NegativeLookBehind@lemmy.world avatar

Why would you never use it?

2xsaiko,
@2xsaiko@discuss.tchncs.de avatar

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.

sneakyninjapants,

Here’s one I have saved in my shell aliases.


<span style="color:#323232;">nscript() {
</span><span style="color:#323232;">    local name="${1:-nscript-$(printf '%s' $(echo "$RANDOM" | md5sum) | cut -c 1-10)}"
</span><span style="color:#323232;">    echo -e "#!/usr/bin/env bashn#set -Eeuxo pipefailnset -e" > ./"$name".sh && chmod +x ./"$name".sh && hx ./"$name".sh
</span><span style="color:#323232;">}
</span><span style="color:#323232;">alias nsh='nscript'
</span>

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.

kayaven,
@kayaven@lemmy.world avatar

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?


<span style="color:#323232;">create_exec() {
</span><span style="color:#323232;">    touch "$1"
</span><span style="color:#323232;">    chmod +x "$1"
</span><span style="color:#323232;">    nano "$1"
</span><span style="color:#323232;">}
</span>

Then you could type create_exec file.sh and it would do the rest for you.

CameronDev,

Write an alias/function to do it and add to your bashrc.


<span style="color:#323232;">function nanox() {
</span><span style="color:#323232;">    nano "$1"
</span><span style="color:#323232;">    chmod +x "$1"
</span><span style="color:#323232;">}
</span>
psmgx,

This is the way.

cyborganism,

You mean like

touch file && chmod +x file ?

MrAlternateTape,

Wrap it up folks, we’re done here.

bjoern_tantau,
@bjoern_tantau@swg-empire.de avatar

You could append the chmod command with && but that’s probably not what you wanted.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • fightinggames
  • All magazines