Announcement

Collapse
No announcement yet.

BASH help please.....

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] BASH help please.....

    If someone can explain this to me I'd appreciate it. I've looked so long and tried so many different ways to correct this I'm afraid I'm just over looking the issue now. The different ways I've tried have all resulted in the same output. I'm trying to create a file name with the Date&Time. Code just below and then below that I'll show the output and would like to know why?

    Code:
    myDATE=`date '+%m%d%Y'`
    myTIME=`date '+%H%M%S'`
    myFl=$myDATE$myTIME".txt"
    echo $myFl
    Output of "echo $myFl". It appears to over-write the previous values in the myFl assignment. Why? What am I doing wrong?

    Code:
    .txt2214
    Last edited by MoonRise; Jan 30, 2014, 08:52 PM.

    #2
    Wow, I cut and pasted all you commands both into a script and in the terminal. Worked as expected here. Really odd...

    Code:
    stuart@office:~$ cat datetest
    myDATE=`date '+%m%d%Y'`
    echo $myDATE
    myTIME=`date '+%H%M%S'`
    echo $myTIME
    myFl=$myDATE$myTIME".txt"
    echo $myFl
    stuart@office:~$
    Code:
    stuart@office:~$ ./datetest
    01292014
    173347
    01292014173347.txt
    stuart@office:~$

    Please Read Me

    Comment


      #3
      Then what the Frick Frack us going on!!? What is at the begining of your script?

      Comment


        #4
        Some ideas:
        • you're not running bash
        • "echo" is aliased to something weird
        • $PROMPT_COMMAND is set to something malformed, which upsets your terminal emulator causing it to eat part of the echo output.
        • "1" and "l" are being confused, even though they're not in your post
        • Try
          kdialog --msgbox $myFl

        Regards, John Little
        Regards, John Little

        Comment


          #5
          Nothing at all in my script except what I posted - what you see is the results of cat, and then the output from the script.

          Please Read Me

          Comment


            #6
            Ach, sometimes the blindingly obvious takes a while to come to mind. You've got DOS line endings; there's a carriage return character (ASCII 13, 0x0d, CR, ctrl-M) at the end of your lines and bash is treating it as just another literal. The time, then the literal ".txt" are overwriting the date. I can reproduce (with a different minute and seconds) your output if I write a script in DOS format.

            If this is new for you ... What editor are you using? A lot of editors transparently flip between DOS, unix and Mac endings, without warning. I use vim and configure it to show in the status line, in a different colour and background, if the file format is not unix. If your editor doesn't offer a straightforward way to fix this then this command will fix it:
            Code:
            sed -i 's/\r//g' [I]script[/I]
            Or you could install "dos2unix" I suppose. (Always seemed overkill to me.)

            Regards, John Little
            Regards, John Little

            Comment


              #7
              Well, that's very interesting John ... and not "blindingly obvious" to me I can assure you ! That puzzle would have had me scratching my head (and losing what little hair I have) very quickly. I tried saving the script with both line ending styles and it does indeed behave the way the OP and you have said. I never would have thought it would do that ... quite a trap for newbies (and not so newbies like myself).
              Desktop PC: Intel Core-i5-4670 3.40Ghz, 16Gb Crucial ram, Asus H97-Plus MB, 128Gb Crucial SSD + 2Tb Seagate Barracuda 7200.14 HDD running Kubuntu 18.04 LTS and Kubuntu 14.04 LTS (on SSD).
              Laptop: HP EliteBook 8460p Core-i5-2540M, 4Gb ram, Transcend 120Gb SSD, currently running Deepin 15.8 and Manjaro KDE 18.

              Comment


                #8
                Originally posted by jlittle View Post
                Ach, sometimes the blindingly obvious takes a while to come to mind. You've got DOS line endings; there's a carriage return character (ASCII 13, 0x0d, CR, ctrl-M) at the end of your lines and bash is treating it as just another literal. The time, then the literal ".txt" are overwriting the date. I can reproduce (with a different minute and seconds) your output if I write a script in DOS format.

                If this is new for you ... What editor are you using? A lot of editors transparently flip between DOS, unix and Mac endings, without warning. I use vim and configure it to show in the status line, in a different colour and background, if the file format is not unix. If your editor doesn't offer a straightforward way to fix this then this command will fix it:
                Code:
                sed -i 's/\r//g' [I]script[/I]
                Or you could install "dos2unix" I suppose. (Always seemed overkill to me.)

                Regards, John Little
                Using KATE but the original file was from Notepad. I'll give a rewrite in Kate and see. Thanks!

                Comment


                  #9
                  Thank you sir! Wasn't really obvious in KATE. Wonder if KATE can be set like VIM? Need to look. Have other applications here that use XML files. For some reason or other, little DOS things like that appear and we are always hunting them down. That doesn't occur often and one reason we have yet isolate why the application does that. Anyway, again, Thanks!

                  Comment


                    #10
                    Just set Kate for UNIX End of Line.
                    Attached Files
                    Using Kubuntu Linux since March 23, 2007
                    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                    Comment


                      #11
                      That makes sense. I used nano for my little test script.

                      Please Read Me

                      Comment


                        #12
                        Originally posted by MoonRise View Post
                        Then what the ...Frack is going on!!?
                        +100 points for BSG reference!
                        samhobbs.co.uk

                        Comment


                          #13
                          Originally posted by Feathers McGraw View Post
                          +100 points for BSG reference!
                          Yeah, I noticed that too! Great SciFi show (I loved the remake of it).
                          Desktop PC: Intel Core-i5-4670 3.40Ghz, 16Gb Crucial ram, Asus H97-Plus MB, 128Gb Crucial SSD + 2Tb Seagate Barracuda 7200.14 HDD running Kubuntu 18.04 LTS and Kubuntu 14.04 LTS (on SSD).
                          Laptop: HP EliteBook 8460p Core-i5-2540M, 4Gb ram, Transcend 120Gb SSD, currently running Deepin 15.8 and Manjaro KDE 18.

                          Comment


                            #14
                            Originally posted by Snowhog View Post
                            Just set Kate for UNIX End of Line.
                            Yep, already had that set. The issue was I edited from an existing file that was done in Windows Notepad for CYGWIN. I guess the combination of CYGWIN and Windows "hid" what was going on. Truthfully I'd never have thought that as I can't actually see the EOL. Is there a way in Kate to make the EOL visible? Don't know but I knew it was something simple I just couldn't figure it out. NOW I know. I won't forget that! Hopefully anyway!

                            Comment


                              #15
                              Originally posted by Feathers McGraw View Post
                              +100 points for BSG reference!

                              Comment

                              Working...
                              X