?
Solved

Bash auto execute *.sh

Posted on 2003-03-12
11
Medium Priority
?
566 Views
Last Modified: 2012-05-04
Hi.

Is it posible that bash automatically execute a script with .sh extension ?
For example, if I have a script named abc.sh,
I just need to type
$./abc

and not
$./abc.sh

How ?

Thanks

0
Comment
Question by:Kocil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Accepted Solution

by:
naccad earned 100 total points
ID: 8122753
that is not possible.
bash/unix in general do not set special values based
on a file extention unlike windows.

the only solution would be to change the file name from
abc.sh to abc

tc
-nick
0
 
LVL 5

Author Comment

by:Kocil
ID: 8122910
Are you sure ?.
I'm using DJGPP Bash on Windows (not the cygwin bash),
and it can do it.
0
 
LVL 5

Author Comment

by:Kocil
ID: 8123039
Are you sure ?.
I'm using DJGPP Bash on Windows (not the cygwin bash),
and it can do it.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 20

Expert Comment

by:Gns
ID: 8124272
If it can, it is surely relying on some windowsism. Or someone has had a bit of fun with the source to make it look like it obeys M$ idiotisms (sorry, perhaps you find it to be "good". I find it to be an abomination;).

You might get somewhere "mapping the filetype" in windoze.
-- Glenn
0
 
LVL 5

Author Comment

by:Kocil
ID: 8124374
It's the BASH features, and that BASH was originally dowloaded from GNU. The documentation said:

===========================
This is a *beta* DOS/DJGPP port of GNU Bash 2.04. This document covers issues specific to DJGPP.

...
/* deleted for brevity */
...

* Executables are found by searching for extensions in this order:
  .com, .exe, .bat, .btm, .sh, .ksh, .pl, .sed
  ls -> ls, ls.com, ls.exe, ls.bat, ls.btm, ls.sh, ls.ksh, ls.pl, ls.sed

So yeah ... I just want to make the calling simple, but keep the file with .sh extension so I can distinguish it.
I'll wait for 3 days, If no other solution/trick to achieve this, I will accept naccad.
0
 
LVL 20

Expert Comment

by:Gns
ID: 8124442
Ok, so someone had a bit of fun with the code then;-).
Stupid suggestion:

As stated, .sh is already  handled special... probably when searching $PATH, so ... add "." to the end of the path:
export PATH=${PATH}:.
Then you should be able to do
$ abc<Enter>
and have it find abc.sh (proviided nothing else matches it before:-).

Or you could look at the source for how the PATH and "exxtensions" are searched, and try copying/moving it so that it will be done for relative paths to scripts/executables too. After all, the source is free:-).

Who you give the points to is entirely at your discretion.
Apart from that, Nick is right (as the initial question was stated), so I would think it only fair for him to recieve them.

-- Glenn
0
 
LVL 4

Expert Comment

by:gletiecq
ID: 8167406
You can alias acb.sh to abc in your bash profile (or at the command line), and that would do the trick.  It would only work for that particular file, but that's the design model here.  If you need to have more files act this way, you can add additional entries.

Greg
0
 
LVL 5

Author Comment

by:Kocil
ID: 8169990
I have been searching about this on google, yahoo, altavista, etc. No luck for me.

So ... time is up.
I have to follow nick suggestion :(

or make softlink
ln -s abc.sh abc

0
 
LVL 20

Expert Comment

by:Gns
ID: 8172506
I understand that you find this feature to be necessary, but one reason most others don't is the excellent completion features of bash. With compspecs you can do amazing things:-). Most stick with the defaults though, and just make a habit of typing <TAB> now and then... But you knew this right?-).

-- Glenn
0
 
LVL 3

Expert Comment

by:naccad
ID: 8173766
Thanks for the points, and a little suggesstion for you.

What I do with custoom scripts is put them in a special
directory, say /opt/scripts or something and then symlink
those to /usr/local/bin

so maybe you can do the same, put abc.sh in  /opt/scripts
and symlink it to /usr/local/bin/abc

I know its not what you want, but it could help

tc
-nick
0
 
LVL 5

Author Comment

by:Kocil
ID: 8179520
Nice trick.
That will do for me.
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question