args or questions in a shell script which is easyer
Linux - NewbieThis forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi,
I am creating a shell script that will save some blender users a lot of time at the moment I have 2 separate scripts the 64 bit version and the 32 bit version the script basically loads the PYTHONPATH and then runs blender but what i wan't to do is have only one script that asks you wether or not your system is 64Bit and if the default command for blender is what you wish to use.
The script currently looks like this
What I was wondering is wether I should use questions or arguments for this and how would i do this?
I realise that scripting at this level may not be classed as a thing so i am sorry if i have placed this in the wrong area of this forum
Last edited by hoodedmanwithsythe; 10-28-2006 at 09:55 AM..
I have to agree with uselpa. If it asks questions, and I'm unable to edit it to accept args instead, then I'm going to need to write an expect script or something if I want to have a default. There seems to be many ways to know the 64 bit answer instead of needing args so you can use those instead.
If there was no way to tell, then you could always define a default value and have a shell variable choose the different path. Much like $EDITOR does. It defaults to vi in most applications if not defined but if defined then the programs will use the editor you want and don't need to prompt you or anything for it.
If you cannot determine about the 64-bit, you may be able to automate using either arguments or an interactive question. If you are called with STDIN being re-directed, you could assume non-interactive, in which case you might look for arguments, otherwise ask a question.
For example:
Code:
#!/bin/sh
# @(#) s2 Demonstrate test for interactive use.
if tty -s
then
echo " YES! Interactive use."
exit 0
else
echo " Not interactive."
exit 0
fi
And a driver:
Code:
#!/bin/sh
# @(#) s1 Drive test for interactive use.
./s2
touch t2
./s2 <t2
Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.
Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.
thanks for the suggestions guys
red=wrong I think I will keep searching I have read about this some where
How about taking hints from FOSS?
Rootkit Hunter uses the distributions release file.
Get Rootkit Hunter then do a "grep 64\) os.dat".
This would require a compiled program that was written in source not in shell and so is not possible sorry but I had already looked at this option.
thinking back to the idea of checking for the /lib64 directory this could solve all problems and no args or other detection would be needed provided that we can find a way of detecting the existance of both that and the blender binarythen the rest would simply be else and elif strings
ok so while trying various things I thought there has to be an easy way of checking the platform type.
I had tried all the obvious and all of the ideas above and came to no end. so when i finally got board of trying various techniques including;
Code:
find /lib64/python2.4 >$HOME/python.lock
if [ "$HOME/Python.lock" = "/lib64/python2.4/*" ]
then etc...
I decided to google for "shell script" and guess what the fist item was "Advanced Bash-Scripting Guide" "An in-depth exploration of the art of shell scripting"
When flicking through it's pages i came across "9.1. Internal Variables" intreagued i scrolled down to find "$HOSTTYPE"
host type
Like $MACHTYPE, identifies the system hardware.
Code:
bash$ echo $HOSTTYPE
i686
and so I ran this on my machine and it came up
Code:
[timothy@Linux-Box ~]$ echo $HOSTTYPE
x86_64
So I thought and then i tested it on my 32bit machine
Code:
[timothy@Slow-Linux-Box ~]$ echo $HOSTTYPE
i386
So it turns out that bash has a builtin platform checker, so i guess it is time for me to get working on the final coding of my blender starter program.
Ok what I have Finaly Decided to do is use the forgotten about built in
Code:
$HOSTTYPE
system variable in a bog standard
Code:
if [ "<Attribute1>" = "<Attribute2>" ]
then <run this>
layout for my PYTHONPATH preloader for blender. At the moment I am going to stick to a simple version of my preloader that doesn't check the python version nor does it check the location of the Blender Wrapper Script.
The reason for this is that I have not worked out how to check the version of python other than with the python -V command(which I cannot channle the output of) and the reason for not checking where the blender Shell Script is because i have made a icon for my preloader and have also made a .desktop for it so as the preloader will now need to reside in /usr/bin or wherever your Blender Wrapper Script (/usr/bin/ is standard location for static versions of blender)resides.
here is my final release of the code
Code:
#!/bin/bash
PATH=/usr/ucb:/usr/bin:/bin; export PATH
# checking the platform
echo "checking Platform"
echo "Platform is "$HOSTTYPE
if [ "$HOSTTYPE" = "x86_64" ]
then #Checking Python Directory
echo "Setting PYTHONPATH for 64Bit OS"
export PYTHONHOME=/usr/lib64/python2.4
export PYTHONPATH=/usr/lib64/python2.4
# loading blender
echo "Running Blender"
./blender
else # setting Python Directory
echo "Setting PYTHONPATH for a 32Bit OS"
export PYTHONHOME=/usr/lib/python2.4
export PYTHONPATH=/usr/lib/python2.4
# loading blender
echo "Running Blender"
./blender
fi
exit
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.