.sh extension needed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting .sh extension needed?
# 1  
Old 06-05-2009
.sh extension needed?

I have a bunch of bash functions in a folder (~/BASH) that I added to my $PATH so that I can call them from anywhere.
Yesterday I stripped the .sh extension from all of them so that I just type the function name without adding .sh every time. Some of the functions still work. Some of them don't unless I type "bash" first, like `bash function`.
Should I just put the extensions back on, or is there a configuration option that I can change?
# 2  
Old 06-06-2009
Make sure you are on the BASH shell when you are calling those functions if they were designed specifically for only BASH. I dont think there is aconfiguration settings as such.


-Devaraj Takhellambam
# 3  
Old 06-06-2009

The extension makes absolutely no difference.

Do make sure that your files are executable:

Code:
chmod +x $HOME/BASH/*

# 4  
Old 06-06-2009
$SHELL is /bin/bash
The file is executable.

But something weird is still happening.

If the file is names bashf I can run it with `bash bashf`.
If I try to run `bashf` then I get an error:
"bash: syntax error near unexpected token `newline'"
If I put the ".sh" extension back on, I can run it simply with `bashf.sh`.

I guess the only real problem is that I can't find the bug in my code. But I'm puzzled why the bug only shows up in 1 of 3 situations.
Maybe I should just include the code. All it does is create a new file with a shabang on the first line:

Code:
#!/usr/bin/env bash

if [ $# -eq 1 ]; then

  if [ -e $1 ]; then
    echo "File already exists. Overwrite? [y/n]";
    read cnfrm;
      if [ "$cnfrm" = "y" ]; then
        echo '' > /dev/null;
      else
        echo 'Cancelling';
        exit 1;
      fi
    fi

  echo "#!/usr/bin/env bash" > $1;
  vi $1;

else
  echo 'Usage: bashf filename';
  echo "Exiting";
  exit 1;
fi

# 5  
Old 06-06-2009
Quote:
Originally Posted by notsomeone
$SHELL is /bin/bash
The file is executable.

But something weird is still happening.

If the file is names bashf I can run it with `bash bashf`.
If I try to run `bashf` then I get an error:
"bash: syntax error near unexpected token `newline'"
If I put the ".sh" extension back on, I can run it simply with `bashf.sh`.

Do you have another file called bashf lying around?

What is the output of:

Code:
type -a bashf bashf.sh

# 6  
Old 06-06-2009
Replace the shebang with:

Code:
#!/bin/bash

# 7  
Old 06-06-2009
Quote:
Originally Posted by Franklin52
Replace the shebang with:

Code:
#!/bin/bash


Why would that make a difference?

(Apart from the fact that his bash executable may not be in /bin, in which case his shebang will work, yours will not.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

Length extension

Ok I have a PERL script that reads an .xml file. One of the new services listed in the file, is alot longer than the others. I am trying to get a way for the spaces of the Service module to read the .xml file and set the length of the %s to the longest Service my $jmsfn = "jms-connection.xml"; ... (2 Replies)
Discussion started by: bigbenn
2 Replies

3. Shell Programming and Scripting

How to print this out without a extension?

i have a file abc.dat that has the below content abc.dat: - 123.dat now, i want to print/output only the below 123 from the file content.( see..i want to chop off .dat extension) kindly advise on this in ksh- i just want to the flag i should pass to the cat command - (2 Replies)
Discussion started by: billpeter3010
2 Replies

4. Shell Programming and Scripting

copying with a certain extension

trying to copy all the files without extension then add "*.txt" but its not working is there any other way and i do not want to use cpio -vdump just want to use copy command FROM=/usr/share/doc TO=/aleza/doc #the follow function copies all the files without extensions call(){ cd $FROM... (3 Replies)
Discussion started by: elginmulizwa
3 Replies

5. Shell Programming and Scripting

Look for more then one extension.

I am currently scanning a directory with a shell script to look for all files with a .sh extension. I am wondering how to make it look for more then one extension. For example all .sh, .conf, and .sql files? Currently this is what I am doing.... find... (3 Replies)
Discussion started by: LRoberts
3 Replies

6. UNIX for Dummies Questions & Answers

extension problem please help

I am executing a program wp1s0000.sh_old and it is executing as expected irrespective of the extension "sh_old" how is this possible ?? (1 Reply)
Discussion started by: sharmasdeepti
1 Replies

7. UNIX for Dummies Questions & Answers

without extension

Hi, I need a help regarding a small requirement. I have a list of C files. I need to put them in a file but without .c extension. say if I have the files as file01.c, file02.c, file03.c etc My file say cfiles should have file01 file02 file03 ... ... etc Appreciate your quick help on... (3 Replies)
Discussion started by: adurga
3 Replies

8. Shell Programming and Scripting

Append extension

Can anyone tell me the easiest way to append an extension (ie. .ldr) to all files in a directory that do NOT have an extension? The directory contains files with and without extensions, however I'm only interested in the files with NO extension. Thanks. (3 Replies)
Discussion started by: here2learn
3 Replies

9. Shell Programming and Scripting

how do i change extension

Hi I am writing a script which does an FTP of a set of files onto another machine and then would have to rename the files into a different extension on the source machine. for example if the file being sent via FTP is sample.txt. Once the file has been transferred i would want to modify the... (2 Replies)
Discussion started by: kswaraj
2 Replies

10. Shell Programming and Scripting

How to change extension?

How do you write a shell script that change the extension of all the files? e.g chext rtf doc where .rtf is the original extension and .doc is the new extension is it something to do with basename? do I need a for loop? Please help! Unix SuperNewbie (4 Replies)
Discussion started by: prkwan
4 Replies
Login or Register to Ask a Question