Does it possible to change path inside bash script?
i have some script with some paths inside it. The idea is to some files which is on desktop copy and move to another location. Problem is that inside script is similar to this:
Code:
cp test.zip /root/help/ because I allways have another zip files, does it possible to have some input which ask me for the name of file, and automaticly change in scripts? Code:
./script Look example. I have zip file called test1..if open my script it wont work cause file to copy in script is test....so how to change that name or whole path inside script. Idea is to use that script inside pcs where is different zip files, and i dont want to change name allways inside scripr. |
You sure about the /root directory?
Code:
echo "file name?" |
Not 100% sure I follow, but assuming I do, why not pass the name of the file to be copied to the script as a parameter and then use that in your copy command?
|
Code:
#!/bin/bash Can you check if code is right writed? It do what I want. Can you just help me, if I want to inside that script to change some conf file. For example in /root/Documents/test.conf to delete some hash tag. in my example of apache2 conf file, i want to DocumentRoot to be without that hashtag... Code:
<VirtualHost *:80> |
Quote:
@tomislav91: grail has a point there. You can call your script with the archive as first parameter, like in Code:
~$ script file-name Code:
FILENAME="$1" |
Quote:
Quote:
|
I need to do some task where default value is commended line. I don't need it. I need when my script do all work, to uncomment that line and restart some service. I think that my last post code is ok, just need this to do.
|
Quote:
|
Why to do manualy? I just posted some example for apache conf, its not that, i just need to uncomment some line in some config file that I maked.
|
So it would appear we have completely changed the initial requirement, ie. there is no longer a cp anywhere in the code.
While your snippet might work, my main objection would be that you never test if the user has supplied the name of an actual file and tested if you have access to it? Code:
mv $var_dir/$var_name.c $var_dir/$var_name.d you never test to see if there already exists a file called 'test.zip.d'. As far as removing the hash, have a look at the sed command. |
Can you give me a little help with sed command?
Yeah, but no worry about that, on Desktop it never will be some file with similar names, and you allways have access to it (if execute command with sudo). |
Show us your sed attempt and where you are stuck?
Here is a link to help :- http://www.grymoire.com/Unix/Sed.html |
i did like this
Code:
sed 's/'#SOMETHING="none"'/'SOMETHING="none"'/' configfile.txt When I did it without, only lefting SOMETHING, than it did work. I tried to put /", but not work either. |
I am confused at why you have so many sets of quotes?? Would you please explain why all the single quotes are needed?
|
Code:
sed 's/#SOMETHING="none"/SOMETHING="none"/' configfile.txt |
All times are GMT -5. The time now is 03:41 AM. |