I get Python. I don't get shell script. I could learn shell script, but I would rather not if I can use Python in its place.
A good place for me to start would be the .profile
script. Currently, for me it is:
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# added by Anaconda2 2.4.0 installer
export PATH="/home/alien/anaconda2/bin:$PATH"
# ===== Added manually.
# texlive
export PATH="/home/alien/texlive/2015/bin/x86_64-linux:$PATH"
export INFOPATH="/home/alien/texlive/2015/texmf-dist/doc/info:$INFOPATH"
export MANPATH="/home/alien/texlive/2015/texmf-dist/doc/man:$MANPATH"
# petsc
export PETSC_DIR="/home/alien/petsc"
# PYTHONPATH
export PYTHONPATH="/home/alien/cncell:$PYTHONPATH"
export PYTHONPATH="/home/alien/csound:$PYTHONPATH"
Instead, I'd like to write something like this:
import os
import subprocess
# if running bash
HOME = os.environ["HOME"]
if os.environ["BASH_VERSION"]: #not sure how to complete this line
bashrc_path = os.path.join(HOME, ".bashrc")
if os.isfile(bashrc_path):
subprocess.call([bashrc_path])
user_bin_dir = os.path.join(HOME, "bin")
if os.isdir(user_bin_dir):
os.environ["PATH"] += ":" + user_bin_dir
user_added_vars = [("PATH", "/home/alien/anaconda2/bin"),\
("PATH", "/home/alien/texlive/2015/bin/x86_64-linux"),\
("INFOPATH", "/home/alien/texlive/2015/texmf-dist/doc/info"),\
("MANPATH", "/home/alien/texlive/2015/texmf-dist/doc/man")]
for var_name, addition in user_added_vars:
os.environ[var_name] += ":" + addition
This is just more readable/familiar to me.
Is it possible to somehow write Python scripts where bash scripts are expected? I think an answer to an earlier question of mine might be useful, perhaps we just stick #!/usr/bin/env python
at the top of the script to designate it as a "Python script"? But then, why isn't there a #!/bin/bash
line at the top of the current .profile
?
bash
as your interactive shell, but in any shell I know about your profile is sourced rather than run as a script.) – Wildcard Dec 10 '15 at 05:21.profile
must be sourced, not run in a subshell, or there'd be no way for them to set shell and environment variables. I can't see how any shell would be able to do that. – Tom Zych Dec 10 '15 at 09:48