You are not logged in.
allow me to start you off with a little history.
i used to be (and still occasionally am) active online in a MOO (which, for the uninitiated, is an object oriented MUD, so in full an Multi User Dungeon Object Oriented - a MOO! - and for all good reasons it is also the sound a cow makes)
these things were originally intended to be for online multiplayer text-games or some shit, but in my case it was filled with my friends and future friends to be, and was essentially a big private chatroom, only with medieval aliases (it is called 'Medieval' and originally themed that way).
in this MOO-environment, you could script all your own stuff (if you had the perms and quota). so, i went wild with making scripts for every conceivable way i could hit, kick, bash, kill, impale or gruesomely mutilate someone (this was all in text, so it was more funny than offensive, and we were among friends)
in this MOO, scripts were called 'verbs', and you could make a new script with the command '@verb crunchbang'. followed by '@edit crunchbang', it would open up in an editor and you'd be making a verb that could be the command 'crunchbang rhowaldt', and the verb would output (for all users in the room to see) 'rhowaldt crunchbangs himself!'
doing a lot of editing, the process of building a verb then editing it became quite tedious: 2 commands for 1 thing!
so, someone made @@verb, which would do @verb followed by @edit.
with bash scripting, each time i make a new script i do
'touch script'
'chmod +x script'
'gedit script &'
so, i figured, let me build a Linux @@verb script, like i had it in the MOO! and so i did. here it is for y'all to see and marvel at and by all means use. i can imagine someone else finding this handy. it is called @script.
#!/bin/bash
# @script will perform a repetitive task for you.
# it will make a new script, make it executable for you,
# then open it in gedit.
LOCATION=`pwd`
PATH=""
TOUCH="/usr/bin/touch"
CHMOD="/bin/chmod"
EDITOR="/usr/bin/gedit"
if [ $# -lt 1 ]; then
echo "Use '@script <scriptname> [<location>]'."
exit
fi
if [ $2 ]; then
if [ ! -d "$2" ]; then
echo "Location does not exist."
exit
else
LOCATION="$2"
fi
fi
PATH="$LOCATION/$1"
$TOUCH $PATH
$CHMOD +x $PATH
$EDITOR $PATHfor old time's sake, i've also added these two to my .bashrc:
# from the MOO-days
alias @verb="@script"
alias @edit="gedit"by the way, if you are wondering why i put the full path to 'pwd', 'touch' and 'gedit' there, it is because for some reason i could not get it working just by name. if someone could help me out on that one, i'd be grateful.
Last edited by rhowaldt (2011-06-19 00:11:42)
Offline
You have to specify the full path to binaries because you use PATH as a script local variable, which obscures your PATH variable, which is the list of directories the system has to search to find executables.
The following version works OK:
#!/bin/bash
_LOCATION=`pwd`
_PATH=""
_TOUCH="touch"
_CHMOD="chmod"
_EDITOR="edit"
if [ $# -lt 1 ]; then
echo "Use '@script <scriptname> [<location>]'."
exit
fi
if [ $2 ]; then
if [ ! -d "$2" ]; then
echo "Location does not exist."
exit 1
else
_LOCATION="$2"
fi
fi
_PATH="$_LOCATION/$1"
$_TOUCH $_PATH
$_CHMOD +x $_PATH
$_EDITOR $_PATHNote the _ in front of script local variables!
Note 2: 'edit' is an alias to emacsclient.
Cheers 
Last edited by xaos52 (2011-08-12 13:32:07)
bootinfoscript - emacs primer - I ♥ #!
Online
@xaos52: thanks for the info man, appreciate it! this will help me in future endeavors.
Last edited by rhowaldt (2011-09-07 20:04:14)
Offline
I'm obviously doing something wrong as I can't get it to work.
I've copied the script into a new file with Geany and made it executable, I've placed the resultant script in ~/bin.
In the Terminal when I type '@script' I get the message:
use '@script <scriptname> [<location>]'So I tried:
@script new [~/bin]but all I get is the message 'location does not exist.'
Could you put out of my misery, please? 
#! Waldorf - 64bit - Xfce
Offline
@rhowaldt will probably come along soon, but until he does, try
@script new ~/binor just
@script new(no brackets around the destination) -- it looks like he's saying the destination is an optional argument, and if you don't specify it the new script will be placed in the directory where you are running @script (that's the return value of `pwd`).
Last edited by 2ManyDogs (2012-03-13 00:17:46)
Be eggsalad to each other.
Offline
^ exactly, thanks for explain Dog! 
i figured i wouldn't have to explain the brackets, as they're a pretty common syntax in manpages and the like. yes, the location is optional. for me, i even forgot that feature was there. i just use
@script myawesomenewscriptOffline
Thanks guys, i was obviously taking it too literally, not being that familiar with scripts etc. 
#! Waldorf - 64bit - Xfce
Offline
^ no problem man! now that you have obtained '@script', you can start getting more familiar with scripts! 
Offline
First exercise, go through @script line-by-line and figure out exactly how it works 
And rhowaldt, I just have to say -- script-writing scripts are bloat 
Be eggsalad to each other.
Offline
2ManyDogs wrote:
And rhowaldt, I just have to say -- script-writing scripts are bloat
Perhaps we could have a script to launch the script writting script? 
No offence meant. 
#! Waldorf - 64bit - Xfce
Offline
^ No, then we'd need a GUI front end for the script-writing script-launcher... 
Be eggsalad to each other.
Offline
^ and GUI's are bad, especially for the minimalist, hence the use of scripts I suppose. 
#! Waldorf - 64bit - Xfce
Offline
'whatever you do, it is probably bloat'
Offline
I get the following when i try running the @script:
kris@kris-inspiron-1720:~/documents$ @script newscript
Warning: unknown mime-type for "/home/kris/documents/newscript" -- using "application/octet-stream"
Error: no "edit" mailcap rules found for type "application/octet-stream"
kris@kris-inspiron-1720:~/documents$ It creates a new text document in ~/documents but does not open it for editing nor does it make it executable.
#! Waldorf - 64bit - Xfce
Offline
^ it uses Gedit... do you have that? or are you on the latest Statler with Geany as an editor? in that last case, open up the code and replace 'gedit' with 'geany' (only problem is can think of here... never seen this error)
Offline
Should i be using the script in your original post or the version in post 2 by xaos52?
When i try your original i don't seem to get anything but when i use the one by xaos52 i get what i posted previously.
#! Waldorf - 64bit - Xfce
Offline
here's the one i'm using currently. if you indeed use Geany as your editor, replace the 'EDITOR' variable in the start of the script.
#!/bin/bash
# @script will perform a repetitive task for you.
# it will make a new script, make it executable for you,
# then open it in gedit.
LOCATION=`pwd`
PATH=""
TOUCH="/usr/bin/touch"
CHMOD="/bin/chmod"
EDITOR="/usr/bin/gedit"
if [ $# -lt 1 ]; then
echo "Use '@script <scriptname> [<location>]'."
exit
fi
if [ $2 ]; then
if [ ! -d "$2" ]; then
echo "Location does not exist."
exit
else
LOCATION="$2"
fi
fi
PATH="$LOCATION/$1"
$TOUCH $PATH
$CHMOD +x $PATH
$EDITOR $PATH &Offline
^excellent, that works a charm. I do indeed use Geany so changed it as you suggested.
I did change it in the previous version I was using but only the one you just posted seemed to work for me.
#! Waldorf - 64bit - Xfce
Offline
You could also do this...
For a shell script (eg @shscript) add this before the last line
echo "#!/bin/bash" > $1
echo "##" >> $1For a python script (eg @pyscript) add
echo "#!/usr/bin/env python" > $1
echo "##" >> $1etc...
Nice idea for a time-saver BTW 
PS How do all you terminalistas keep track of all your scripts and shell commands?
Artwork at deviantArt; Iceweasel Personas; GDM #! Themes;
SLiM #! Themes
Offline
^ my scripts are in ~/scripts (with subdirectories for C, Python, and whatever else i'm gonna be embarking on). aliases are in ~/.rhowaldt_bashrc
i just remember what scripts i have because i use them quite regularly. if i don't remember, i navigate to my scripts-dir and see what the name of that particular script was.
shell-commands: see my signature, the 'system' link. i just do 'system ref' and get a list of handy commands for various functions.
Offline
@rhowaldt.. How do execute your scripts?
I save mine in the 'bin' folder as below:
~/bin/@scriptand then I execute the script from the terminal. However if I save the script in another folder say:
~/scripts/@scriptsthen i cannot execute the script from the terminal anymore. 
#! Waldorf - 64bit - Xfce
Offline
Is ~/scripts/@scripts in your PATH?
Be eggsalad to each other.
Offline
^ apologies for the noob in me, but how do I tell?
#! Waldorf - 64bit - Xfce
Offline
Sorry, I should have explained that. If you don't know, it probably isn't, but to check do this:
echo $PATHThen if it's not there, open ~/.bashrc, and add this at the end:
#add @scripts and bin folders to path
PATH=$PATH:~/scripts/@scripts:~/bin
export PATHIf that doesn't work we can try something else.
Be eggsalad to each other.
Offline
^ It wasn't in the path so I added the code to the .bashrc file, unfortunately it still says command not found.
#! Waldorf - 64bit - Xfce
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.