Emacs 29 Edition is out now!


Make script files executable automatically

Quick trick to force all shell scripts to have the execute bit set on file save
4 comments

You can force Emacs to make a file executable (respecting your umask settings) if Emacs considers it a script. To determine if it is a script, Emacs will look for the hash-bang notation in the file and treat it as a script if it finds it.

Add this to your init file and Emacs will then make the file executable if it is a script.

(add-hook 'after-save-hook
  'executable-make-buffer-file-executable-if-script-p)

Further Reading

Have you read my Reading Guide yet? It's a curated guide to most of my articles, and I guarantee you'll learn something whether you're a beginner or an expert. And why not check out my book?

Subscribe to the Mastering Emacs newsletter

I write infrequently, so go on — sign up and receive an e-mail when I write new articles

Copyright 2010-24 Mickey Petersen. Terms & Privacy Policy (Last updated 2022-05-24.)