LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2009, 09:30 AM   #1
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Rep: Reputation: 37
[BASH] variable assignment help


Hi guys,

I have this piece of code here:

Code:
#!/bin/bash
# zipit.sh

folder=$1
zip -rm ${folder}.zip $folder
mv -t ../done ${folder}.zip
What happens is that I will be doing that over and over again for a few days so I decided to create a little script for it but I dont know if you could guess it... it creates a small problem...

when I do zipit M[TAB] to auto complete the auto complete adds a "/" at the end of the folder name, and what the script does is that it creates a file named ".zip" with the contents inside...

The question is, how can i assign folder=$1 but deleting the "/"... or perhaps a more correct variable expansion in ${folder}.zip would help? but im not sure about it since im little new in bash scripting.

Any other suggestions are appreciated.
 
Old 08-30-2009, 09:34 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look in the bash info manual for variable expansion.

file="${1%/}.zip"
 
Old 08-30-2009, 10:28 AM   #3
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Original Poster
Rep: Reputation: 37
Thanks, I will read it today.
 
  


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
about immediate and deferred variable assignment in GNU make George2 Programming 1 07-22-2011 05:55 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
trivial: bash, local variable assignment agrestic Linux - Newbie 3 01-27-2009 11:30 AM
Java String variable re-assignment Cyhaxor Programming 9 11-24-2007 03:35 PM
Bash assignment - using a grep inside an if statement lowpro2k3 Programming 4 03-25-2005 05:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 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
Open Source Consulting | Domain Registration