Find the answer to your Linux question:
Results 1 to 2 of 2
Given the following code I am expecting the variable NewFile to be: myfile.txt.pdf However my system is returning the following: ".pdfest.txt" without quotes. Code: FileName=`head $f -n1 | awk -F/ ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    3

    Bash script variable substitution help



    Given the following code I am expecting the variable NewFile to be: myfile.txt.pdf
    However my system is returning the following: ".pdfest.txt" without quotes.

    Code:
                    FileName=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'`
                    #this returns "myfile.txt" no quotes
                    Ext="${FileName##*.}"
                    xPdf=".pdf"
                    fn="${FileName}"
    
                    NewFile="${fn}${xPdf}"
    Any help is appreciated, please note that I am newb and know little to nothing about linux.

  2. #2
    Just Joined! clickalot's Avatar
    Join Date
    Nov 2009
    Location
    Erlangen, Germany
    Posts
    37
    that's strange...


    i tried:
    Code:
    #!/bin/bash
    
    # FileName=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'`
    #this returns "myfile.txt" no quotes
    FileName=myfile.txt
    
    Ext="${FileName##*.}" # no effect on outcome
    xPdf=".pdf"
    fn="${FileName}"
    NewFile="${fn}${xPdf}"
    
    echo $NewFile
    # outputs: myfile.txt.pdf
    it does what is expected.
    are you sure you're using bash...?

Posting Permissions

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