[opensuse] BASH script help needed - Why is full path required?
Listmates, Bash gurus I'm stuck again with a BASH problem that I don't fully understand. I am working with my ATI driver install script and for some reason I must provide the full path name for rpm to be able to install the file, but from everything I see, it should work with a relative path or simply the file name since the script is executed in the same directory as the file. I have underlined the rpm call that is giving me the problem of needing the full path-to-the-rpm. The relative parts of the script are: # ## Assign the Driver Release variable input from the command line before calling ## other functions. Otherwise search for the latest fglrx rpm in the current ## directory, selecting the newest, and test that it is readable. If not found, exit # if [ -n "$1" ]; then FGLRX_RPM="$1" else FGLRX_RPM=$(ls fglrx*.rpm | tail -1) if [[ -n $FGLRX_RPM ]]; then echo -e "\n\t\tSelecting: $FGLRX_RPM\n" fi fi <snip> # ## Ready to Install. Prompt to confirm install or exit # echo -e "\n\tPrepared to Install $FGLRX_RPM\n" read -p "Continue? (yes/no): " INSTALL if [ "$INSTALL" == "yes" ] || [ "$INSTALL" == "Yes" ] || [ "$INSTALL" == "YES" ]; then echo -e "\n\tInstalling $FGLRX_RPM....\n" if [[ ! -r ${FGLRX_RPM} ]]; then echo -e "\n\tUnable to find the fglrx rpm to install.\n\n\tPlease specify the file as a command line option or make sure it is in the present working directory.\n\tExiting\n" exit 1 fi if rpm -Uvh ${FGLRX_RPM}; then ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ echo -e "Install of ${FGLRX_RPM}\T\TSucceeded!\n" else echo -e "rpm -Uvh ${FGLRX_RPM}\T\TFAILED!\nyou will have to install manually -- bummer\n" fi ## Restore the xorg.conf cp /tmp/xorg.conf /etc/X11/xorg.conf else echo -e "\n\tYou chose NOT to install the driver, you will have to install manually\n" echo -e "\n\twith \'rpm -Uvh $FGLRX_RPM\'\n" ## Restore the xorg.conf cp /tmp/xorg.conf /etc/X11/xorg.conf exit 1 fi I don't understand why rpm will error out and say "File not found" unless the full path is given? I can execute the command outside of the script just fine giving only the filename of the rpm, but for some reason when called from inside the script, rpm wants the full path specified. I have tried using different forms of the variable like $FGLRX_RPM and "$FGLRX_RPM", but still the problem. If I pass the full path information, it works just fine. I have also tried passing ./fglrx-rpm-name.rpm since expansion takes ./ as a full path, but that doesn't seem to work either. What is baffling is that even when the rpm is automatically selected from the present directory both the initial echo -e "\n\t\tSelecting: $FGLRX_RPM\n" and the confirmation prompt echo -e "\n\tPrepared to Install $FGLRX_RPM\n" show the proper rpm filename just like you would enter at the command line. However, without the full path, rpm can't find the file. So, admitting defeat, I thought I would post and at least get another pair of eyes on how I'm handling the $FGLRX_RPM variable to see if anybody else could spot why I'm having to pass the full path information to make rpm happy. Thanks! -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 16 October 2008 20:26, David C. Rankin wrote:
Listmates, Bash gurus
I'm stuck again with a BASH problem that I don't fully understand. I am working with my ATI driver install script and for some reason I must provide the full path name for rpm to be able to install the file, but from everything I see, it should work with a relative path or simply the file name since the script is executed in the same directory as the file. I have underlined the rpm call that is giving me the problem of needing the full path-to-the-rpm. The relative parts of the script are:
Nothing jumps out. But I gather we're not seeing the entire script. What does the sh-bang line look like? My guess is that it does not include the "--norc" command, which means that your ~/.bashrc is being executed. Could that be changing the current working directory? I always recommend this sh-bang line: #!/bin/bash --norc ...
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Thursday 16 October 2008 20:26, David C. Rankin wrote:
Listmates, Bash gurus
I'm stuck again with a BASH problem that I don't fully understand. I am working with my ATI driver install script and for some reason I must provide the full path name for rpm to be able to install the file, but from everything I see, it should work with a relative path or simply the file name since the script is executed in the same directory as the file. I have underlined the rpm call that is giving me the problem of needing the full path-to-the-rpm. The relative parts of the script are:
Nothing jumps out. But I gather we're not seeing the entire script. What does the sh-bang line look like? My guess is that it does not include the "--norc" command, which means that your ~/.bashrc is being executed. Could that be changing the current working directory?
I always recommend this sh-bang line:
#!/bin/bash --norc
...
-- David C. Rankin
Randall Schulz
Hmm.. I'll give it a try Randall. Also means sudo may be giving me some trouble as well. Thanks. -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 16 October 2008 21:37, (David C. Rankin) wrote:
Randall R Schulz wrote:
On Thursday 16 October 2008 20:26, David C. Rankin wrote:
Listmates, Bash gurus
I'm stuck again with a BASH problem that I don't fully understand. ...
Nothing jumps out. But I gather we're not seeing the entire script. What does the sh-bang line look like? My guess is that it does not include the "--norc" command, which means that your ~/.bashrc is being executed. Could that be changing the current working directory?
I always recommend this sh-bang line:
#!/bin/bash --norc
I should add that this has to primary effects / motivations: 1) Faster start-up of the script, since ~/.bashrc isn't processed 2) Shell configuration / variable settings / options are in a known state (the environment is as inherited, of course).
...
-- David C. Rankin
Randall Schulz
Hmm..
I'll give it a try Randall. Also means sudo may be giving me some trouble as well. Thanks.
I don't see a sudo invocation in what you wrote. If you're using it, you should review the manual page, 'cause the processing it does prior to executing the specified command is non-trivial and could conceivably be interfering. I'm not that well-versed in sudo, so I can't give details, but I just glanced at the man page.
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, Oct 17, 2008 at 06:02:10AM -0700, Randall R Schulz wrote:
On Thursday 16 October 2008 21:37, (David C. Rankin) wrote:
Randall R Schulz wrote:
On Thursday 16 October 2008 20:26, David C. Rankin wrote:
Listmates, Bash gurus
I'm stuck again with a BASH problem that I don't fully understand. ...
Nothing jumps out. But I gather we're not seeing the entire script. What does the sh-bang line look like? My guess is that it does not include the "--norc" command, which means that your ~/.bashrc is being executed. Could that be changing the current working directory?
I always recommend this sh-bang line:
#!/bin/bash --norc
I should add that this has to primary effects / motivations:
1) Faster start-up of the script, since ~/.bashrc isn't processed
There is no option required, AFAIK the bash never source ~/.bashrc nor /etc/bash.bashrc ... to test this run bash -x yourscript and compare with bash -x as interactive shell.
2) Shell configuration / variable settings / options are in a known state (the environment is as inherited, of course).
Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 17 Oct 2008, 15:02:10 +0200, Randall R Schulz wrote:
On Thursday 16 October 2008 21:37, (David C. Rankin) wrote:
Randall R Schulz wrote:
On Thursday 16 October 2008 20:26, David C. Rankin wrote:
Listmates, Bash gurus
I'm stuck again with a BASH problem that I don't fully understand. ...
Nothing jumps out. But I gather we're not seeing the entire script. What does the sh-bang line look like? My guess is that it does not include the "--norc" command, which means that your ~/.bashrc is being executed. Could that be changing the current working directory?
I always recommend this sh-bang line:
#!/bin/bash --norc
I should add that this has to primary effects / motivations:
1) Faster start-up of the script, since ~/.bashrc isn't processed 2) Shell configuration / variable settings / options are in a known state (the environment is as inherited, of course).
It actually _can_ have effects... I've seen such .*rc files which contained some arbitrary "cd $HOME" commands in them... To address the OPs problem, I'd add some "pwd" commands to find out which directory the script/interpreter believes to stay in. HTH, cheers. l8er manfred -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
(David C. Rankin)
-
David C. Rankin
-
Dr. Werner Fink
-
Manfred Hollstein
-
Randall R Schulz