why won't scripts work unless i 'source' them?

why won't scripts work unless i 'source' them?

Post by UNLIST » Wed, 13 Sep 1995 04:00:00



        i'm using SunOS 4.1.3. when i write a shell script called test that
contains one line:

                        echo "Hi there"

and i make it executable with "chmod +x test", if i then type test or ./test
at the command prompt, the script does not execute. it only executes if i type
"source test". why is that? even weirder, if i create another script which
 contains one line,

                        tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0

and make it executable, lo and behold, it works! what's the deal?

 
 
 

why won't scripts work unless i 'source' them?

Post by Duane Bolt » Wed, 13 Sep 1995 04:00:00


:       i'm using SunOS 4.1.3. when i write a shell script called test that
: contains one line:

:                       echo "Hi there"

: and i make it executable with "chmod +x test", if i then type test or ./test
: at the command prompt, the script does not execute. it only executes if i type
: "source test". why is that? even weirder, if i create another script which
:  contains one line,

:                       tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0

: and make it executable, lo and behold, it works! what's the deal?

Man "test" ... try renaming your script "TEST" and see if if runs
(I'll bet it will!)

Duane
--
     +-------------------------------------------------------------------+

     +-------------------------------------------------------------------+

 
 
 

why won't scripts work unless i 'source' them?

Post by Youri N. Podchos » Wed, 13 Sep 1995 04:00:00



writes:
|>   i'm using SunOS 4.1.3. when i write a shell script called test that
|> contains one line:
|>
|>                   echo "Hi there"
|>
|> and i make it executable with "chmod +x test", if i then type test or ./test
|> at the command prompt, the script does not execute. it only executes if i
|> type
|> "source test". why is that? even weirder, if i create another script which
|>  contains one line,
|>
|>                   tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0
|>
|> and make it executable, lo and behold, it works! what's the deal?

Call your script something else: "test" is a valid unix command implemented
as a binary executable and often linked to "[" to be used in Bourne/Korn
shell statements like
   if test -f SOMEFILE; then ...; fi           or
   if [ -f SOMEFILE ]; then ....; fi

+---------------------------------------------------------------------+
| Youri N. Podchosov (ynp) * Davidsohn & Son, Inc. NYC * 718-234-4140 |

+---------------------------------------------------------------------+

 
 
 

why won't scripts work unless i 'source' them?

Post by Igor Skapink » Thu, 14 Sep 1995 04:00:00


The problem is the name of the script.

Tnen you run at the command prompt

% test

the '/usr/bin/test' is called because the directory /usr/bin is before the
current directory in the PATH. Your script is not called.

But ./test should work.

So, change the name of the script and it will work.

Igor.

 
 
 

why won't scripts work unless i 'source' them?

Post by Simon Bur » Thu, 14 Sep 1995 04:00:00





>>                         echo "Hi there"
>> and i make it executable with "chmod +x test", if i then type test or ./test
>> at the command prompt, the script does not execute.

Do you have the line

#!/bin/sh

At the head of the script ? If not, then it is not surprising. This line tells
the kernel (AFAIR) to run the rest of the script through the command listed
after the "#!" bit. Naturally, this means that you can also execute other
command interpreter such as perl, awk, sed, etc.

If you didn't have that line, its not surprising that you had to use "source
test" to run the script. Its better to doing things like "sh test" though, as
"source test" just runs the commands as if you've typed the command into the
shell your running in directly... so things can change from shell to shell.
If you use "sh test" then you know what shell is being used.

Quote:>Try altering the name to something else.  Anythign except 'test' as
>'test' is a shell command!

Nope, as they used ./test as well, ie execute the command test in the current
working directory.

--

Systems Manager and Programmer       |   Total Connectivity Providers Ltd
          I *don't* speak for my company, my boss does that
                      Is there an LD50 for chocolate ?

 
 
 

why won't scripts work unless i 'source' them?

Post by Cage » Thu, 14 Sep 1995 04:00:00



 >   i'm using SunOS 4.1.3. when i write a shell script called test that
 > contains one line:
 >
 >                   echo "Hi there"
 >
 > and i make it executable with "chmod +x test", if i then type test or ./test
 > at the command prompt, the script does not execute. it only executes if i type
 > "source test". why is that? even weirder, if i create another script which
 >  contains one line,
 >
 >                   tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0
 >
 > and make it executable, lo and behold, it works! what's the deal?

Just a guess, here, but did you try adding

     #!/bin/sh

to your script?  I'll admit that both scripts work fine on my linux box using
BASH, but it's possible that other shells may treat scripts differently.  I'm
guessing that that may solve your problem as 'echo' is a shell-specific command
while 'tar' is a separate binary.

hth
--
                                   wWw
+-----------------------          (o o)        ------------------------+
|Kurt Granroth          \------ooO-(_)-Ooo-----\                       |
|Computer Science Major  \ Linux: The choice of \ Damn the torpedoes,  |

|Phone: (906) 482-4588     \----------------------\                    |
+---------------------------                       --------------------+
                       http://metro.turnpike.net/G/gran

 
 
 

why won't scripts work unless i 'source' them?

Post by Sally Woolric » Thu, 14 Sep 1995 04:00:00




Quote:>         i'm using SunOS 4.1.3. when i write a shell script called test that
> contains one line:

>                         echo "Hi there"

> and i make it executable with "chmod +x test", if i then type test or ./test
> at the command prompt, the script does not execute. it only executes if i type
> "source test".

Try altering the name to something else.  Anythign except 'test' as
'test' is a shell command!

--
============================================================================
Sally Woolrich                    |          This mail contains my personal

============================================================================

 
 
 

why won't scripts work unless i 'source' them?

Post by Frank San » Fri, 15 Sep 1995 04:00:00




>    i'm using SunOS 4.1.3. when i write a shell script called test that
> contains one line:
>                    echo "Hi there"
> and i make it executable with "chmod +x test", if i then type test or ./test
> at the command prompt, the script does not execute. it only executes if i type
> "source test". why is that? even weirder, if i create another script which
>  contains one line,

>                    tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0

> and make it executable, lo and behold, it works! what's the deal?

     Several other posters responded that it doesn't work because test
is a built in command of the shell.  I have tried this script under
SunOS 4.1.3 and found the following:

     Under csh the script works fine using either test or ./test
Under bsh (where test is a command) the script works fine with ./test
but fails with just test.  I believe this is the expected behavior.

     The original poster did not state what shell he was using, but I
can't think of any shell where ./test wouldn't work.  Since he used the
source command, it appears that he is using a csh or one of its
variants.

---

 
 
 

why won't scripts work unless i 'source' them?

Post by Edmund Bac » Fri, 15 Sep 1995 04:00:00




>|> >  i'm using SunOS 4.1.3. when i write a shell script called test that
>                                                                  ^^^^
>  'test' already exists in your shell or .../bin/test. Try './test'.
>  I've only been caught out by this a few hundred times....

Too right.  I now call all my test functions 'tst' --- you can tell
which systems I've been on by the tst, tst.o and tst.c droppings ...

----------

  The Moving FInger write; and, having writ
  Moves on: nor all thy Peity nor Wit
    Shall lure it back to cancel half a Line,
  Nor all thy Tears wash out a Word of it.


 
 
 

why won't scripts work unless i 'source' them?

Post by Ray A. Jon » Sun, 17 Sep 1995 04:00:00



:  >         i'm using SunOS 4.1.3. when i write a shell script called test that
:  > contains one line:
:  >
:  >                         echo "Hi there"
:  >
:  > and i make it executable with "chmod +x test", if i then type test or ./test
:  > at the command prompt, the script does not execute. it only executes if i type
:  > "source test". why is that? even weirder, if i create another script which
:  >  contains one line,
:  >
:  >                         tar cvf - /vmunix | rsh remote_box dd of=/dev/rst0
:  >
:  > and make it executable, lo and behold, it works! what's the deal?

: Just a guess, here, but did you try adding

:      #!/bin/sh

: to your script?  I'll admit that both scripts work fine on my linux box using

[rest deleted]

No guys, the reason (I hit the same problem several years ago) is the name
of your script, "test".  There is a Unix utility in /bin/test that is
executed PRIOR to your local "test" program because it is in the PATH first.

Just change the name of your script to ANYTHING not already in the PATH.
When you "source" the program, that looks in the current directory for
"test" not the one in the PATH, /bin/test.
--

URL: http://www.celestial.com         One Mercer Plaza, Suite S100
                                      Mercer Island, WA 98040; (206) 236-1676
Manufacturer of InterRack (Internet-in-a-Rack), a full turn-key
system, including all the hardware, software, installation, setup, training
and support for businesses and Internet Service Providers

 
 
 

1. chmod won't work unless I'm the owner, or root

I'm trying to chmod a file that I have group permission on, but I'm not the
owner.  And it won't do it.  Please point me in the right direction...

Chmod, chown won't work.  But cat will.  So therefore I don't think it's a
permission problem, but something I'm missing with chmod, Linux RedHat
9.0(I'm an old HP-UX guy where this works fine), or something I've setup (or
not setup) with security...

Side note:  I noticed this when actually trying to change the bits thru
Samba, which led me to the fundamental Linux question.

Thanks,
Chris

Details below:

The file looks like:
$ls -l tempo
-rw-rw-r--    1 foobar1  users           10 May 22 09:54 tempo
$

I am logged in as "chris", not "foobar1" with a gid of 100 (users).  I.e.
different uid, same gid.

This is being done in /tmp which looks like "drwxrwxrwt   12 root     root
4096 May 22 09:54 tmp"

The error message is:
$chmod 666 tempo
chmod: changing permissions of `tempo': Operation not permitted
$

$chmod --version
chmod (coreutils) 4.5.3
Written by David MacKenzie.

Copyright (C) 2002 Free Software Foundation, Inc.
$
$uname -a
Linux fatbstd 2.4.18-18.8.0 #7 Fri Dec 6 09:53:30 PST 2002 i686 i686 i386
GNU/Linux
$

2. FTP server behind firewall

3. Help with shell script; 'tput clear' won't work!?!

4. Fetchmail problem

5. 'make' won't work w/o '-f Makefile', which sucks.

6. Linux Frequently Asked Questions with Answers (Part 4 of 6)

7. Kingston KNE20T's why won't they work?

8. telnet & samba work, but ftp doesn't

9. Pseudo-tty's What are they, why won't rxvt work?

10. Linux IP Masq & Netmeeting -- here's why it won't work

11. Why doesn't my ppp-on script work when su'ing

12. PROBLEM: 'sed' script 's/^ /\n/' not working properly

13. Can't Get PPP Working - Chat (ppp-on) script won't dial