|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
How to return argument of command line?
I want to change the href path in many files. So, i write a simple script and save it into a file to run it.
for i in filename1, filename2 do sed 's/src=/src=..\/page\//' $i > change.tmp cp -f change.tmp $i done so, in order to change some specific file, i hv to go into the file and change the filename manually.. I wish to make it more effective that it can return the argument of unix commandl line and run the program. so, i no need to hardcored the filename in the script. eg. change a.html # change is the script name, so, a.html will pass into the change file and run the script inside change the path of a.html. anyone can give me some idea how to do it? Druuna, i hope u can see this message and teach me how to do.. thanks... |
|
#2
|
|||
|
|||
|
I'm not certain that I understand the question.
This is what I think you want: 1) change href="whatever" to href="your-choice" in a specific file. 2) give the name of the file(s) to change as option to a script. Another question: What do the original scr="...." look like, or are they empty. I need to know this because of the regular expression that needs to be constructed for the sed statement. Last edited by druuna : November 21st, 2003 at 10:52 AM. |
|
#3
|
|||
|
|||
|
drunna, actually wat u understand is correct.
here is the situation, there are some files tat i need to change the file path for each files. So, i dun wan manually change it one by one. So, i wan to write some script and included all those file in tat script in order to run the process. for the src question, ../page is go out for the current directory and get into another page directory! I test it, it is work properly.. so, no need to bother abt this question. my question is there any shell script tat can retrieve or return the argument of the unix command? |
|
#4
|
|||
|
|||
|
The command line arguments are passed to shell scripts via $1, $2, $3, ...; "$*" contains all of them.
#!/bin/sh for i in $*; do ... Second solution: put them in a text file, say /tmp/files.txt then use: for i in `cat /tmp/files.txt`; do ... Another one: pipe the file to the script and make the script read from stdin: cat /tmp/files.txt | script.sh (or: script.sh < /tmp/files.txt) while read filename; do... hth, M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. Last edited by M.Hirsch : November 27th, 2003 at 12:56 PM. |
|
#5
|
|||
|
|||
|
Thanks for the so many alternative solution..
I try all of those solution. The first one work perfectly.. But the second and third solution is not working. For the second solution, i put the file.txt and the script.sh into same directory. some error msg appear like this : "cannot find and open file cat" for i in 'cat file.txt' do sed 's/src=/src=..\/page\//' $i > change.tmp cp -f change.tmp $i done for the third solution, it appear msg like "file.txt : this is not an identifier" while read file.txt do sed 's/src=/src=..\/page\//' $i > change.tmp cp -f change.tmp $i done May i noe y this kinds of errors appear? Thanks~ |
|
#6
|
|||
|
|||
|
#2 failed because this is supposed to be backticks, not single quotes. ` not '
But on second thought, don't use it. I guess it will fail when filenames contain spaces (untested). #3 was a little misleading, sorry, I should have said some more words. "filename" was the variable name here. So: script.sh: Code:
#!/bin/sh while read i do sed 's/src=/src=..\/page\//' "$i" > change.tmp cp -f change.tmp "$i" done And then: ./script.sh < ./files.txt Also add the quotes around "$i" to deal with spaces in filenames. hth, M. |
|
#7
|
|||
|
|||
|
Thanks M.Hirsch~ I test it again with ur instruction. All is work perfectly~
Thanks to drunna also, u help me a lots too~ I am very glad found this forum with so many helpful frens here~ Have a nice day, guys! Thanks a lots!!! |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > How to return argument of command line? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|