BASH Shortcuts

From PrattWiki
Revision as of 13:36, 6 February 2019 by DukeEgr93 (talk | contribs)
Jump to navigation Jump to search

The following is a list of shortcuts Pratt students may want to add to their .bashrc profile. This, first of all, assumes that they are using the bash shell. To check this, type

echo $SHELL 

If the result is

/bin/bash

than this page applies to you; if not, see the TCSH Shortcuts page.


Required .bash_profile File

If you are a bash shell user, you will also need to have a .bash_profile in your CIFS home directory (the ~ directory) for the shortcuts to work. The contents of the profile should be:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
      . ~/.bashrc 
fi  

# User specific environment and startup programs
PATH=$PATH:$HOME/bin

export PATH

Main Shortcuts

EGR 103 Lab Startup

You can create a script to automate the process of getting the tar file, expanding it, and making a local copy. This command should only be used once you have created the appropriate labN folder in your EGR103 folder and should only be used if you have changed into that folder! Type pwd first to make sure you are in the right place! You can add the following to your .bashrc file:

get103(){
LabNum=$1;
wget people.duke.edu/~mrg/EGR103public/Lab${LabNum}Files.tar
tar -kxvf Lab${LabNum}Files.tar
cp -i Lab${LabNum}Sample_S19.tex lab${LabNum}.tex
}

and then if you log out and log back in (or type source ~/.bashrc, from that point forward, once you are in the correct directory, you can type the command

get103 N

where N is the appropriate lab number and this will get the tar file from Dr. G's web space, expand it, and make a local copy of the lab skeleton in labN.tex.

latex and dvipdf in One Command

Now that you need to run both latex and dvipdf to get a PDF file for evince to look at, you may want to have a shorter way than having to type

latex FILE.tex
dvipdf FILE.dvi

every time. To make a /bin/bash shortcut for that, add the following to your .bashrc file:

ltx() {
MyFile=$1
MyFile=${MyFile%%.*}
latex $MyFile.tex
dvipdf $MyFile.dvi
}

Note that to use it, you do not need to include the ".tex" at the end of your file name, but you can. The script will automatically take the extension off whatever you gave as an input.

If you want a version that does some basic error-checking, use this one:

ltx() {
MyFile=$1;
MyFile=${MyFile%%.*}
 
if [[ -f $MyFile.tex ]]
then
   latex $MyFile.tex
   dvipdf $MyFile.dvi
else
  echo "*ERROR*: '$MyFile.tex' not found"
fi
}

From that point on, once the .bashrc runs to start your session, you can simply type

ltx FILE

or

ltx FILE.tex

and it will run

latex FILE.tex
dvidf FILE.dvi