New #!'er and newish linux user here. Just starting to learn a bit more about bash scripting and I've found it tedious creating the file, opening it to edit, chmod'ing it then executing it with ./.
So, I decided to knock up a quick script that will create a /bin folder in my home dir then add it to the $PATH, take the 1st argument and create a file with that name, chmod it to allow execution and then open it up in your fave editor (yes im a nano man, what of it!)
Haven't tested it yet as I'm at work on my Windows box but thought I'd share it anyway and see what you think / show me where I've gone wrong etc
#!/bin/bash #========================================================================== # TITLE: mksh (MaKe SHell) # AUTHOR: MarcDJay # # USAGE: mksh <scriptname> # DESCRIPTION: Creates a file with given argument, copies it to ~/bin, # makes the file executable and then opens it in your editor # of choice. #========================================================================== # Edit the following and replace with your favourite editor EDITOR=changeme # Checks to see if the command already exists, and if it does quits. which $1 | $(ishere) if $ISHERE [ != "" ] echo "Command already exists! Terminating..." echo "" sleep 1s exit fi # Check if ~/bin exists, and if not, create it & add to PATH if [ ! -d "~/bin" ]; then mkdir ~/bin echo "PATH="$PATH:$HOME/bin"" >> ~/.profile fi # Creates the file to become the script touch $HOME/bin/$1 echo "#!/bin/bash" >> $1 # Makes the file executable chmod +x $HOME/bin/$1 # Opens file in your editor $EDITOR $HOME/bin/$1 exit
Looks a little like rhowaldt's @script: http://crunchbanglinux.org/forums/topic/13759/script/
^ it is indeed exactly the same principle.
nice script DJ Marc! makes a lot of sense to create this indeed.
Great idea. I have always used a template that I made in geany but often forget to open the template and eventually get pissed at myself because I finish the script and realize I left out the summary, etc. have to open the template and copy it all back in etc. A script to write scripts is just crazy enough that my addled brain will remember it. As they said in Blazing Saddles "stand back, I think he's just crazy enough to do it".
Find something useful here? Help fund CrunchBang, donate to the project!