bash scripting... taking user input and adding it to a particular area of a file...
in bash scripting...say I want to take the input from a user via a question...I would do this:
Quote:
The portion of /etc/fstab that uses /dev/shm for the tmpfs partition is: tmpfs /dev/shm tmpfs defaults 0 0 So, if a user says "24" GB to the answer (from above), how do I get it to automatically add that value to the tmpfs partition line in /etc/fstab? So it would look like: tmpfs /dev/shm tmpfs size=24g,defaults 0 0 I understand that I would also have to come up with a way to put "size=XXg", which I could do with a copied over generic file before this action...then the script would have to find "XX" and replace it with the user's figure... Anyone have any ideas? |
Code:
var="size=${PART_SIZE}g" Sasha |
Quote:
I probably should have stated that I am somewhat of a n00b in scripting...but I will try this solution out... again, thanks! |
Code:
NOTE: I also edited my first post, and put the {braces} around the variable; I neglected to do that the first time, which would have led to the variable being empty, because it would have thought the 'g' was part of the variable name. My apology. Sasha |
Quote:
|
Cool! Glad it helped. Now, it's up to you to learn what exactly the command is doing ;) so that you can do stuff like this with other variables, or other replacements, etc.
The sed man page doesn't list even a fraction of what sed can do, but the sed documentation and lots of tutorials can be found easily on the net. Cheers! Sasha |
Quote:
|
Like someone's signature around here reads: "Sed & Awk -- never leave home without them!"
Best of success in learning them; there's a lot to them, but one example at a time is the way to go. Soon, you'll see it isn't too hard to go from a short simple sed or awk function, to a longer more complex one, because it's really just 'more of the same'. PS - you'll notice I used double-quotes around the sed function. The reason is so that the $variable would be properly interpreted as a shell variable. With single quotes, it would have been taken literally. Usually though, single quotes are used around sed statements. You're welcome :) and best of success. Sasha |
All times are GMT -5. The time now is 11:06 PM. |