Logo 
Search:

Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

Script not working

  Date: Dec 04    Category: Unix / Linux / Ubuntu    Views: 429
  

I'm trying to learn to use the shell and I have this script that I have seen
posted in several different places, and I want to put in my .bashrc.

However, I get the following error: line 11: syntax error near unexpected
token
line 11: syntax error "function extract()

I don't know enough yet to spot what's wrong.

Can anyone help?

Here's the script.

function extract() # Handy Extract Program.

{

if [ -f $1 ] ; then

case $1 in

*.tar.bz2) tar xvjf $1 ;;

*.tar.gz) tar xvzf $1 ;;

*.bz2) bunzip2 $1 ;;

*.rar) unrar x $1 ;;

*.gz) gunzip $1 ;;

*.tar) tar xvf $1 ;;

*.tbz2) tar xvjf $1 ;;

*.tgz) tar xvzf $1 ;;

*.zip) unzip $1 ;;

*.Z) uncompress $1 ;;

*.7z) 7z x $1 ;;

*) echo "'$1' cannot be extracted via >extract<" ;;

esac

else

echo "'$1' is not a valid file"

fi

}

Share: 

 

1 Answer Found

 
Answer #1    Answered On: Dec 04    

I think I see the error - it appears to be in the function declaration.

You have parens there, and I think that's causing the error.

"Declaring a function is just a matter of writing function my_func {
my_code }.
"
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html

Missing from your script was the the interpreter path (not
sure if it was left off when you copy/pasted or if it it's
missing from your actual bash script.

On some systems this line looks like

#!/usr/local/bin/bash
or
#!/usr/bin/bash

but for portability, I usually use
#!/bin/sh
and because of systematic symlinks, it "finds" the bash
interpreter path wherever it may happen to be.

 
Didn't find what you were looking for? Find more on Script not working Or get search suggestion and latest updates.




Tagged: