LinuxQuestions.org
Register a domain and help support LQ
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, 11: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 11:59 AM.
 
Old 04-24-2014, 12:07 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
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, 12:33 PM   #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 12:51 PM.
 
Old 04-24-2014, 12:59 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

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

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:19 PM
[SOLVED] pass shell parameters to awk does not work kristo5747 Linux - Newbie 2 06-20-2011 12:40 PM
[SOLVED] bash how pass array as one of several parameters to a function porphyry5 Programming 5 06-14-2011 10:11 PM
[SOLVED] wget passing URL parameters doesn't seem to work nonshatter Linux - Software 3 10-04-2010 08:48 AM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 06:30 PM


All times are GMT -5. The time now is 05:50 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration