Results 1 to 4 of 4
Hey everyone!
So, I'm trying to create and write to a file with a script.
I know how to create the file with touch.
I know how to write to ...
- 08-05-2009 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 9
Script to create file
Hey everyone!
So, I'm trying to create and write to a file with a script.
I know how to create the file with touch.
I know how to write to the file with echo and >> / >
but, I'm having problems writing special characters, in particular, "$" and a quotation mark.
So, when I put this line in my script...
echo "case "$1" in" >> file.txt
it obviously doesn't write it out correctly, as it won't write the $ or the " mark.
Also, when I do...
echo "cd $JAVA_HOME/bin/" >> file.txt
it doesn't correctly write out my variable, as I assume it is trying to replace it with the variable value. Is there a way I can write the $ into another file with my script?
I know it's probably a relatively easy question, but I've searched everywhere on the internet and can't seem to find anything about it.
Nevermind, it's just \$ or \". Bah, took me way too long to figure that out!
- 08-05-2009 #2
What is more, you can use apostrophes ('), which keep the literal meaning of anything they embrace. They prevent variable expansion for example.
Code:system:~$ echo "$HOME" /home/gnufan system:~$ echo '$HOME' $HOME
Debian GNU/Linux -- You know you want it.
- 08-05-2009 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 9
Okay, now I have a legitimate question, how do you copy the contents of a file and append them to the contents of another file?
- 08-05-2009 #4Just Joined!
- Join Date
- Aug 2009
- Posts
- 9
Nevermind, apparently you can copy contents into another file with cat and >>.
Thanks for the tip GNU-Fan, I'm going to use your idea as that looks a lot prettier and much more intuitive.
I'll try to post some GOOD questions sometime soon.


Reply With Quote