Help with linux questions please

FloOzFloOz Member Posts: 1,614 ■■■■□□□□□□
so i am just beginning my studies on linux. I am currently reading an old book my teacher gave me and unfortunatly the answer pages are torn out. I have ones questions that i need some help on.

the question asks to describe what each line of the script does.

i understand what #!/bin/bash does, however, after that im stumped. thank you for any help

[FONT=Arial, sans-serif]#!/bin/bash[/FONT]
[FONT=Arial, sans-serif]myFile=Test.txt[/FONT]
[FONT=Arial, sans-serif]touch $myFile[/FONT]
[FONT=Arial, sans-serif]date > $myFile[/FONT]
[FONT=Arial, sans-serif]date +%Y%m%d >> $myFile[/FONT]
[FONT=Arial, sans-serif]date +%F >> $myFile[/FONT]
[FONT=Arial, sans-serif]date +%F--%k:%M >> $myFile[/FONT]
[FONT=Arial, sans-serif]myFile=Test_$(date +%F--%k:%M).txt[/FONT]
[FONT=Arial, sans-serif]touch $myFile


[/FONT]

Comments

  • brownwrapbrownwrap Member Posts: 549
    This is a script. You should be able to execute each entry on the command line and see the results.
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    What in your understanding does each of these lines do? Post your take on it so other can comment. If you don't know what >, >>, $myFile mean, it's a good idea to start with a Bash tutorial first.
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • brownwrapbrownwrap Member Posts: 549
    brownwrap wrote: »
    This is a script. You should be able to execute each entry on the command line and see the results.

    myFile=Test.txt

    ls -larth
    total 12
    drwx
    30 ramosg staff 4.5K Feb 17 13:39 ../
    drwx
    2 ramosg staff 512 Feb 17 13:41 ./
    -rw
    1 ramosg staff 0 Feb 17 13:41 Test.txtdate > $myFile


    ls -larth
    total 14
    drwx
    30 ramosg staff 4.5K Feb 17 13:39 ../
    drwx
    2 ramosg staff 512 Feb 17 13:41 ./
    -rw
    1 ramosg staff 29 Feb 17 13:41 Test.txt



    [ramosg@appoc9 tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    [ramosg@appoc9 tmp]$

    date +%Y%m%d >> $myFile


    [ramosg@appoc9 tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    20120217


    date +%F >> $myFile

    [ramosg@appoc9 tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    20120217
    2012-02-17
    [ramosg@appoc9 tmp]$


    date +%F--%k:%M >> $myFile

    [ramosg@appoc9 tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    20120217
    2012-02-17
    2012-02-17--14:15
    [ramosg@appoc9 tmp]$

    myFile=Test_$(date +%F--%k:%M).txt

    [ramosg@appoc9 tmp]$ echo $myFile
    Test_2012-02-17--14:16.txt
    [ramosg@appoc9 tmp]$

    [ramosg@appoc9 tmp]$ touch $myFile
    [ramosg@appoc9 tmp]$ ls -larth
    total 14
    drwx
    30 ramosg staff 4.5K Feb 17 13:39 ../
    -rw
    1 ramosg staff 67 Feb 17 14:15 Test.txt
    drwx
    2 ramosg staff 512 Feb 17 14:18 ./
    -rw
    1 ramosg staff 0 Feb 17 14:18 Test_2012-02-17--14:16.txt
    [ramosg@appoc9 tmp]$








    [ramosg@appoc9 tmp]$
Sign In or Register to comment.