Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

Bash auto execute *.sh

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
Kocil
Asked:
Kocil
  • 5
  • 3
  • 2
  • +1
1 Solution
 
naccadCommented:
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
 
KocilAuthor Commented:
Are you sure ?.
I'm using DJGPP Bash on Windows (not the cygwin bash),
and it can do it.
0
 
KocilAuthor Commented:
Are you sure ?.
I'm using DJGPP Bash on Windows (not the cygwin bash),
and it can do it.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
GnsCommented:
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
 
KocilAuthor Commented:
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
 
GnsCommented:
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
 
gletiecqCommented:
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
 
KocilAuthor Commented:
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
 
GnsCommented:
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
 
naccadCommented:
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
 
KocilAuthor Commented:
Nice trick.
That will do for me.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now