LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 09-10-2006, 07:22 AM   #1
1kyle
Member
 
Registered: Feb 2004
Location: 'Ol Blighty
Distribution: SLED 10, SUSE 10.3
Posts: 722

Rep: Reputation: 32
cannot execute a script unless prefix ./


Silly problem but can't seem to solve this one

I create a script in a directory /home/user/scripts.

Add the directory to the path via export

try and run script xxxx.sh

always get command not found (even as root and none of the commands in the script need root access).

cd /home/userid/scripts

try again --still command not found

Run however with ./xxxx.sh it works

I shouldn't have to prefix the script with ./

I just want to type in the command and have the script execute -- ideally as xxxx

Googled around --plenty of tutorials on creating scripts but none of them seem to explain how do you run them just as a command

cheers

-K
 
Old 09-10-2006, 07:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You mention adding the dir to the PATH variable, did that work (echo $PATH to check)?
Does your script start with the appropriate 'she-bang' (#!/bin/bash for example)?
Does your script have execute permissions (rwxr-xr-x or alike)?

Hope this gets you going again.
 
Old 09-11-2006, 06:00 AM   #3
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: Ubuntu
Posts: 3,517

Rep: Reputation: 58
For safety reasons, the current directory is not included in your path variable. There are good reasons, however I can't remember any good examples. That's why the ./ is required. If you want to run this script, copy it to a location that is in $PATH (e.g. /usr/local/bin). To find out what's in your users path, type 'echo $PATH'. If you don't care about safety, you can add the current directory to your path by adding the following line to ~/.bashrc (or /etc/profile.local ?):

Code:
export PATH=$PATH:.
EDIT (found an example):
Quote:
Imaging you write a script and call it "ls" then save it in a folder where you have access, let's say /tmp. Now if you get your admin to run "ls" in /tmp as root and have "." in the PATH, that will run your script instead of running the real "ls". This way you can do some nasty trick. This is why "." is not in your PATH.

Last edited by abisko00; 09-11-2006 at 06:04 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why prefix shell script with "./" ? seeDubya Linux - Newbie 5 08-29-2005 01:53 AM
Cannot execute a script grueugene Programming 15 01-27-2005 04:50 AM
Shell Script (adding a prefix to output lines) rheza Programming 3 01-04-2005 01:18 PM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 01:30 PM
Why cant i execute a perl script dude4you Linux - Newbie 2 03-02-2004 05:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 12:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration