From 2f2900213cc8157590f11dcc7988c1a3bb7dc887 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 20 Apr 2015 19:31:17 -0400 Subject: Be careful about shebangs, which shells are used, and what gets executed Use - #!/hint/bash for bash that gets sourced (non-executable) - #!/hint/sh for sh(1) that gets sourced (non-executable) - #!/bin/sh for sh(1) that gets executed - #!/usr/bin/env bash for bash that gets executed To this end, also - Clean up a couple of related comments - Fix a couple of bash-isms that I noticed in sh(1) files - Fix permissions on a couple of files that get sourced --- .config/X11/clientrc | 2 +- .config/X11/login | 9 ++------- .config/X11/serverrc | 2 +- .config/bash/login.sh | 5 ++--- .config/bash/logout.sh | 3 ++- .config/bash/rc.d/aliases.sh | 4 +--- .config/bash/rc.d/emacs.sh | 2 +- .config/bash/rc.sh | 4 +++- .config/login.d/00_coredumps.sh | 1 + .config/login.d/00_path.sh | 1 + .config/login.d/00_umask.sh | 1 + .config/login.d/01_xdg.sh | 2 +- .config/login.d/02_xdg_runtime_dir.sh | 2 +- .config/login.d/03_tmpdir.sh | 1 + .config/login.d/10_gpg.sh | 1 + .config/login.d/10_java.sh | 1 + .config/login.d/10_less.sh | 1 + .config/login.d/10_selected-editor.sh | 3 ++- .config/login.d/10_spell-check.sh | 3 ++- .config/login.d/10_xauthority.sh | 3 ++- .config/login.d/90_symlink_xdg_runtime_dir.sh | 1 + .config/login.sh | 17 ++++++----------- .config/symlinks | 1 + .config/wmii-hg/config.sh | 2 +- .config/wmii-hg/help-events | 2 +- .config/wmii-hg/help-keys | 2 +- .config/wmii-hg/include.sh | 2 +- .config/wmii-hg/quit | 2 +- .config/wmii-hg/rbar | 2 +- .config/wmii-hg/rbar.sh | 2 +- .config/wmii-hg/rbar_acpi | 2 +- .config/wmii-hg/rbar_clock | 2 +- .config/wmii-hg/rbar_wifi | 2 +- .config/wmii-hg/theme-solarized | 1 + .config/wmii-hg/theme-solarized-dark | 2 +- .config/wmii-hg/theme-tango | 1 + .config/wmii-hg/theme-tango-dark | 2 +- .config/wmii-hg/util.sh | 2 +- .config/wmii-hg/wmiirc | 2 +- 39 files changed, 52 insertions(+), 48 deletions(-) mode change 100755 => 100644 .config/X11/clientrc diff --git a/.config/X11/clientrc b/.config/X11/clientrc old mode 100755 new mode 100644 index 2c965da..88ae527 --- a/.config/X11/clientrc +++ b/.config/X11/clientrc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/hint/sh # Load system xinit modules (disabled) # Remove "false &&" to enable diff --git a/.config/X11/login b/.config/X11/login index 84931df..d02088a 100755 --- a/.config/X11/login +++ b/.config/X11/login @@ -1,9 +1,4 @@ #!/bin/sh +# ~/.xsession: Executed by the XDM at login, maybe after sourcing ~/.xprofile -# -# ~/.xsession -# -# Executed by xdm/gdm/kdm at login -# - -exec bash --login -i ~/.xinitrc +exec bash --login ~/.xinitrc diff --git a/.config/X11/serverrc b/.config/X11/serverrc index 6b57eeb..e6f4c8f 100644 --- a/.config/X11/serverrc +++ b/.config/X11/serverrc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/hint/sh if [ -z "$XDG_VTNR" ]; then exec /usr/bin/X -nolisten tcp "$@" else diff --git a/.config/bash/login.sh b/.config/bash/login.sh index 1269a03..08f26b8 100644 --- a/.config/bash/login.sh +++ b/.config/bash/login.sh @@ -1,6 +1,5 @@ -# ~/.bash_login: executed by bash(1) when login shell starts. - -# I think this is sane default behavior +#!/hint/bash +# ~/.bash_login: Sourced by bash(1) when login shell starts # Load user settings . "$HOME/.profile" diff --git a/.config/bash/logout.sh b/.config/bash/logout.sh index 5dd8f7d..623f0a0 100644 --- a/.config/bash/logout.sh +++ b/.config/bash/logout.sh @@ -1,4 +1,5 @@ -# ~/.bash_logout: sourced by bash(1) when login shell exits. +#!/hint/bash +# ~/.bash_logout: Sourced by bash(1) when login shell exits # Clear the screen for privacy's sake. clear diff --git a/.config/bash/rc.d/aliases.sh b/.config/bash/rc.d/aliases.sh index 28b9923..6b2460e 100644 --- a/.config/bash/rc.d/aliases.sh +++ b/.config/bash/rc.d/aliases.sh @@ -1,6 +1,4 @@ -#!/bin/bash -# The above line probably should never be *used* in this file, but it -# lets text editors know that this is BASH syntax. +#!/hint/bash ###################################################################### # Set up colors and settings for ls/dir/vdir # diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh index bb6454b..d8e1d80 100644 --- a/.config/bash/rc.d/emacs.sh +++ b/.config/bash/rc.d/emacs.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash if [[ $TERM == eterm* ]]; then SELECTED_EDITOR='emacsclient' diff --git a/.config/bash/rc.sh b/.config/bash/rc.sh index ae55d5c..70f1ce4 100644 --- a/.config/bash/rc.sh +++ b/.config/bash/rc.sh @@ -1,4 +1,6 @@ -# ~/.bashrc: executed by bash(1) for interactive non-login shells. +#!/hint/bash +# ~/.bashrc: Sourced by bash(1) for interactive non-login shells +# # I include this file for all interactive invocations of bash(1), whether # they are login shells or not. diff --git a/.config/login.d/00_coredumps.sh b/.config/login.d/00_coredumps.sh index 8fcc61b..45d19b8 100644 --- a/.config/login.d/00_coredumps.sh +++ b/.config/login.d/00_coredumps.sh @@ -1 +1,2 @@ +#!/hint/sh ulimit -c unlimited # save core dumps diff --git a/.config/login.d/00_path.sh b/.config/login.d/00_path.sh index f4ca3a6..2d5f4a5 100644 --- a/.config/login.d/00_path.sh +++ b/.config/login.d/00_path.sh @@ -1,3 +1,4 @@ +#!/hint/sh if type config-path &>/dev/null; then config_path=config-path else diff --git a/.config/login.d/00_umask.sh b/.config/login.d/00_umask.sh index 8e71ad5..c6187dd 100644 --- a/.config/login.d/00_umask.sh +++ b/.config/login.d/00_umask.sh @@ -1 +1,2 @@ +#!/hint/sh umask 022 diff --git a/.config/login.d/01_xdg.sh b/.config/login.d/01_xdg.sh index 22bbc01..ed17ddb 100644 --- a/.config/login.d/01_xdg.sh +++ b/.config/login.d/01_xdg.sh @@ -1,4 +1,4 @@ -# This should be readable by /bin/sh +#!/hint/sh # Sets up XDG environmental variables, so programs using them don't have to # worry about checking if they are set. diff --git a/.config/login.d/02_xdg_runtime_dir.sh b/.config/login.d/02_xdg_runtime_dir.sh index 6d93359..6700669 100644 --- a/.config/login.d/02_xdg_runtime_dir.sh +++ b/.config/login.d/02_xdg_runtime_dir.sh @@ -1,4 +1,4 @@ -# This should be readable by /bin/sh +#!/hint/sh # Set XDG_RUNTIME_DIR if we can if [ -z "$XDG_RUNTIME_DIR" ] && shopt -q login_shell && type flock &>/dev/null; then diff --git a/.config/login.d/03_tmpdir.sh b/.config/login.d/03_tmpdir.sh index b94ef1a..62413a7 100644 --- a/.config/login.d/03_tmpdir.sh +++ b/.config/login.d/03_tmpdir.sh @@ -1,3 +1,4 @@ +#!/hint/sh if [ -n "$XDG_RUNTIME_DIR" ]; then mkdir -p -- "$XDG_RUNTIME_DIR/tmpdir" export TMPDIR="$XDG_RUNTIME_DIR/tmpdir" diff --git a/.config/login.d/10_gpg.sh b/.config/login.d/10_gpg.sh index cf3c88c..c1c5f82 100644 --- a/.config/login.d/10_gpg.sh +++ b/.config/login.d/10_gpg.sh @@ -1,3 +1,4 @@ +#!/hint/sh if [[ -z $GPGKEY ]] && [[ -f "${HOME}/.gnupg/gpg.conf" ]]; then export GPGKEY=`sed -nr 's/^\s*default-key\s+//p' "${GNUPG_HOME:-${HOME}/.gnupg}/gpg.conf"` fi diff --git a/.config/login.d/10_java.sh b/.config/login.d/10_java.sh index 3c49368..94452a9 100644 --- a/.config/login.d/10_java.sh +++ b/.config/login.d/10_java.sh @@ -1,3 +1,4 @@ +#!/hint/sh _JAVA_OPTIONS='' _JAVA_OPTIONS+=' -Dawt.useSystemAAFontSettings=on' _JAVA_OPTIONS+=' -Dswing.aatext=true' diff --git a/.config/login.d/10_less.sh b/.config/login.d/10_less.sh index c5934d6..314a8b9 100644 --- a/.config/login.d/10_less.sh +++ b/.config/login.d/10_less.sh @@ -1,2 +1,3 @@ +#!/hint/sh export LESSHISTFILE="$XDG_CACHE_HOME/less/histfile" mkdir -p -- "${LESSHISTFILE%/*}" diff --git a/.config/login.d/10_selected-editor.sh b/.config/login.d/10_selected-editor.sh index f176b8a..52696cd 100644 --- a/.config/login.d/10_selected-editor.sh +++ b/.config/login.d/10_selected-editor.sh @@ -1,4 +1,5 @@ -if [[ -f "$HOME/.selected_editor" ]]; then +#!/hint/sh +if [ -f "$HOME/.selected_editor" ]; then . "$HOME/.selected_editor" export SELECTED_EDITOR export ALTERNATE_EDITOR diff --git a/.config/login.d/10_spell-check.sh b/.config/login.d/10_spell-check.sh index 9a24b7e..3f67b8f 100644 --- a/.config/login.d/10_spell-check.sh +++ b/.config/login.d/10_spell-check.sh @@ -1,3 +1,4 @@ -if [[ -z "$DICTIONARY" ]] && [[ -n "$LANG" ]]; then +#!/hint/sh +if [ -z "$DICTIONARY" ] && [ -n "$LANG" ]; then export DICTIONARY="${LANG%%.*}" fi diff --git a/.config/login.d/10_xauthority.sh b/.config/login.d/10_xauthority.sh index a27202c..787b6ed 100644 --- a/.config/login.d/10_xauthority.sh +++ b/.config/login.d/10_xauthority.sh @@ -1,4 +1,5 @@ +#!/hint/sh # This was needed once with SSH and Fedora boxes. -if [[ -z $XAUTHORITY ]]; then +if [ -z $XAUTHORITY ]; then export XAUTHORITY="$HOME/.Xauthority" fi diff --git a/.config/login.d/90_symlink_xdg_runtime_dir.sh b/.config/login.d/90_symlink_xdg_runtime_dir.sh index bc6109d..7ee4bba 100644 --- a/.config/login.d/90_symlink_xdg_runtime_dir.sh +++ b/.config/login.d/90_symlink_xdg_runtime_dir.sh @@ -1,3 +1,4 @@ +#!/hint/sh # This is really only needed for ssh ControlPath; as I don't have a # way to communicate XDG_RUNTIME_DIR if [ -n "$XDG_RUNTIME_DIR" ]; then diff --git a/.config/login.sh b/.config/login.sh index 538920a..9499299 100644 --- a/.config/login.sh +++ b/.config/login.sh @@ -1,15 +1,10 @@ -#!/bin/bash -# ~/.profile: executed by the command interpreter for login shells. -# I like that graphical login scripts be configured to load this, so -# it always runs, graphical or not. +#!/hint/sh +# ~/.profile: Sourced by the command interpreter for login shells # -# This file should be executable by /bin/sh, but I'm going to assume bash(1) -# -# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login -# exists. - -# the default umask is set in /etc/profile; for setting the umask -# for ssh logins, install and configure the libpam-umask package. +# Other ~/.*profile scripts may take precedence, or be used instead +# (for example: ~/.bash_{profile,login} takes precidence, and +# ~/.xprofile is used for graphical logins). I dislike duplication, +# so I have them all configured to source this. if [ -z "$HOME" ]; then eval 'HOME=~' diff --git a/.config/symlinks b/.config/symlinks index af0f1af..066a7e0 100644 --- a/.config/symlinks +++ b/.config/symlinks @@ -26,6 +26,7 @@ .config/irbrc .irbrc .config/linphonerc .linphonerc # .config/selected_editor .selected_editor +.config/X11/login .vnc/xstartup .config/offlineimaprc .offlineimaprc .cache/offlineimap .offlineimap diff --git a/.config/wmii-hg/config.sh b/.config/wmii-hg/config.sh index ac0a349..6846920 100644 --- a/.config/wmii-hg/config.sh +++ b/.config/wmii-hg/config.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash MODKEY=Mod4 # "super" UP=p diff --git a/.config/wmii-hg/help-events b/.config/wmii-hg/help-events index 08abd18..9aeb3e9 100755 --- a/.config/wmii-hg/help-events +++ b/.config/wmii-hg/help-events @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash . include.sh scansection Event | xmessage -file - diff --git a/.config/wmii-hg/help-keys b/.config/wmii-hg/help-keys index 6f4bd1c..f7a975e 100755 --- a/.config/wmii-hg/help-keys +++ b/.config/wmii-hg/help-keys @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash . include.sh scansection Key | xmessage -file - diff --git a/.config/wmii-hg/include.sh b/.config/wmii-hg/include.sh index f9e3078..4e86276 100644 --- a/.config/wmii-hg/include.sh +++ b/.config/wmii-hg/include.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash if [[ -z "$WMII_NAMESPACE" ]]; then export WMII_NAMESPACE="$(wmiir namespace)" diff --git a/.config/wmii-hg/quit b/.config/wmii-hg/quit index 341468e..b34a913 100755 --- a/.config/wmii-hg/quit +++ b/.config/wmii-hg/quit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if type systemctl &>/dev/null; then systemctl --user stop "wmii@$DISPLAY.service" else diff --git a/.config/wmii-hg/rbar b/.config/wmii-hg/rbar index b95f9c4..0709ed3 100755 --- a/.config/wmii-hg/rbar +++ b/.config/wmii-hg/rbar @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash id=$1 name=${id#[0-9][0-9]_} diff --git a/.config/wmii-hg/rbar.sh b/.config/wmii-hg/rbar.sh index 8bff558..0c9efa6 100644 --- a/.config/wmii-hg/rbar.sh +++ b/.config/wmii-hg/rbar.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash setup_trap() { trap "rm -f -- \"\${XDG_RUNTIME_DIR}\"/n/wmii*/rbar/${1}" EXIT } diff --git a/.config/wmii-hg/rbar_acpi b/.config/wmii-hg/rbar_acpi index bdcdf0f..6348873 100755 --- a/.config/wmii-hg/rbar_acpi +++ b/.config/wmii-hg/rbar_acpi @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash update() { id=$1 diff --git a/.config/wmii-hg/rbar_clock b/.config/wmii-hg/rbar_clock index a09f016..e84d5c3 100755 --- a/.config/wmii-hg/rbar_clock +++ b/.config/wmii-hg/rbar_clock @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash update() { id=$1 diff --git a/.config/wmii-hg/rbar_wifi b/.config/wmii-hg/rbar_wifi index f83d921..dad4e61 100755 --- a/.config/wmii-hg/rbar_wifi +++ b/.config/wmii-hg/rbar_wifi @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash iwinfo() { local interface=$1 diff --git a/.config/wmii-hg/theme-solarized b/.config/wmii-hg/theme-solarized index 5dc830d..8c40e4d 100644 --- a/.config/wmii-hg/theme-solarized +++ b/.config/wmii-hg/theme-solarized @@ -1,3 +1,4 @@ +#!/hint/bash SOL_BASE03='#002b36' SOL_BASE02='#073642' SOL_BASE01='#586e75' diff --git a/.config/wmii-hg/theme-solarized-dark b/.config/wmii-hg/theme-solarized-dark index fde361b..fc74b6c 100644 --- a/.config/wmii-hg/theme-solarized-dark +++ b/.config/wmii-hg/theme-solarized-dark @@ -1,4 +1,4 @@ -#!/bin/sh +#!/hint/bash # Solarized-dark . theme-solarized diff --git a/.config/wmii-hg/theme-tango b/.config/wmii-hg/theme-tango index f4c20a2..6ba744f 100644 --- a/.config/wmii-hg/theme-tango +++ b/.config/wmii-hg/theme-tango @@ -1,3 +1,4 @@ +#!/hint/bash TANGO_butter=("#fce94f" "#edd400" "#c4a000") TANGO_orange=("#fcaf3e" "#f57900" "#ce5c00") TANGO_choc=( "#e9b96e" "#c17d11" "#8f5902") diff --git a/.config/wmii-hg/theme-tango-dark b/.config/wmii-hg/theme-tango-dark index 04a9fa6..efea1e9 100644 --- a/.config/wmii-hg/theme-tango-dark +++ b/.config/wmii-hg/theme-tango-dark @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash # Tango-tark . theme-tango diff --git a/.config/wmii-hg/util.sh b/.config/wmii-hg/util.sh index b28a3b6..55344b2 100644 --- a/.config/wmii-hg/util.sh +++ b/.config/wmii-hg/util.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/hint/bash ################################################################################ # Added shell features # diff --git a/.config/wmii-hg/wmiirc b/.config/wmii-hg/wmiirc index 6fd348f..260aaa1 100755 --- a/.config/wmii-hg/wmiirc +++ b/.config/wmii-hg/wmiirc @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash unset WMII_NAMESPACE unset WMII_DIR -- cgit v1.1-4-g5e80