LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2014, 10:53 AM   #1
eudald
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Rep: Reputation: 1
Pass parameters through bash doesn't work


Hi all,
First of all, apologises for main topic, but I'm not able to change its name.

I'm writting a script in bash with some functions and it doesn't work properly.

For example, which is what happens:
Code:
compFunct(){
  $1 $3.$2 $4
}

#main
vDest="/tmp/export/file"
vOrig="/tmp/export/filedest"
echo "Compression method: "
read vCompression
case $vCompression in
  zip)
     vFormat="zip"
     ;;
  tar.gz)
     vFormat="tar -czvf"
     ;;
  *)
     echo "Unknown compression format"
     ;;
esac
compFunct $vFormat $vCompression $vDest $vOrig
For the first case it works, but not for the second. I think there migh be any problem with the space or cause these are options, but I don't know.

Errormessg:
Code:
tar -czvf: command not found
Any clues?
Thanks,
Eudald

Last edited by eudald; 04-24-2014 at 10:59 AM.
 
Old 04-24-2014, 11:07 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
What is your input command?

Have you tried putting #!/bin/bash -x at the top and running again for additional error output? Try that.
 
1 members found this post helpful.
Old 04-24-2014, 11:33 AM   #3
eudald
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Original Poster
Rep: Reputation: 1
Hi szboardstretcher,
There's no input on this script,

Thanks for your tip, I've noticed that the function takes the parameter as a whole cause I changed IFS at the beggining of the script for other needs.

I'll change that and will check if it works.

Edit: It works, thanks once again

Eudald

Last edited by eudald; 04-24-2014 at 11:51 AM.
 
Old 04-24-2014, 11:59 AM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
That's why you should always paste your whole script when troubleshooting Glad you got it worked out.
 
Old 04-24-2014, 12:28 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
I would be curious to know how it worked? If you reset IFS back to its original value your 4 positional arguments will move and be incorrect as vFormat unquoted will now yield:
Code:
$1 - tar
$2 - -cvf
$3 - tar.gz
$4 - /tmp/export/file
Hence the original source will no longer be part of what the function compFunct sees. So either you changed more than just resetting IFS or your version of bash behaves really differently??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Loop through list of URLs in txt file, parse out parameters, pass to wget in bash. dchol Linux - Newbie 16 07-27-2011 02:19 PM
[SOLVED] pass shell parameters to awk does not work kristo5747 Linux - Newbie 2 06-20-2011 11:40 AM
[SOLVED] bash how pass array as one of several parameters to a function porphyry5 Programming 5 06-14-2011 09:11 PM
[SOLVED] wget passing URL parameters doesn't seem to work nonshatter Linux - Software 3 10-04-2010 07:48 AM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 05:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration