LinuxQuestions.org
Review your favorite Linux distribution.
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-07-2016, 05:16 AM   #16
tomislav91
Member
 
Registered: Apr 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled

i was so confused either, primarly because it works like this
Code:
sed 's/'#SOMETHING=none'/'SOMETHING=none'/' configfile.txt
without "" in
Quote:
none
word. So i was confused why with it don't work. Thanks, now works. Can you point me to some improvments of that code? I will added to my bash script this command:

Code:
echo -n "give a name for script [ENTER]: "
read var_name
var_dir="/root/Documents/test"
unzip -o $var_name -d  $var_dir
mv $var_dir/$var_name.c $var_dir/$var_name.d
sed 's/#SOMETHING="none"/SOMETHING="none"/' configfile.txt
service something restart
 
Old 08-07-2016, 07:48 AM   #17
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by tomislav91
Code:
unzip -o $var_name -d  $var_dir
If $var_name is a zip file, question should be more like
"Give the zip filename"

Last edited by keefaz; 08-07-2016 at 07:50 AM.
 
Old 08-07-2016, 12:47 PM   #18
tomislav91
Member
 
Registered: Apr 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
Thanks, that helps, but this text i random writed now, I know that that question is better

Some other suggestions?

What about zip name? What If I enter just a name of zip file with .zip in given name? Script wont move file, because it cant find anything like that. For example.
I have a file with name test.zip and inside that file test.c, I want to that test.c renamed in test.d, and my script does that job, but only if I in first question give a name just TEST, without .ZIP. How to solve that?

Last edited by tomislav91; 08-07-2016 at 01:06 PM.
 
Old 08-07-2016, 01:36 PM   #19
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Easy way is to asking for name then add ".zip" for unzipping (with error checking test if file exists or not)
 
Old 08-07-2016, 03:08 PM   #20
tomislav91
Member
 
Registered: Apr 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
You mean to add .zip with this
Code:
unzip -o $var_name -d  $var_dir
to be
Code:
unzip -o $var_name.zip -d  $var_dir
 
Old 08-07-2016, 07:19 PM   #21
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Yes, or "$var_name.zip" (added quotes in case of spaces in filename)
 
Old 08-07-2016, 09:31 PM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Or you can remove it but it depends on the flow of your code and how many times it needs to be added or removed to use the best option for you.
To remove:
Code:
${var_name%.zip}
 
  


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
script to read path from console and used to change the script execution path vdamgo Linux - General 5 02-12-2013 02:18 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 01:05 PM
export $PATH inside script gmitra Programming 3 02-01-2005 08:34 AM

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

All times are GMT -5. The time now is 05:18 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