Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I need a little help with variablestuff... How do I save a variable as a filename? Tried: Code: read §filename new_file (read in program) echo 'filecontent' > '~/§filename' Result: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2013
    Posts
    1

    Make variable into filename


    Hi, I need a little help with variablestuff...
    How do I save a variable as a filename?
    Tried:
    Code:
    read §filename
    new_file (read in program)
    echo 'filecontent' > '~/§filename'
    Result:
    Code:
    ~/§filename: ambiguous redirect
    Would like:
    Code:
    ~/new_file is a dir...
    grateful for any suggestions!

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    899
    ~/ is a shortcut for the current user's home directory.

    Anyway, you should write the echo line like this:
    echo 'filecontent' > ~/"$filename"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •