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



    [[email protected] tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    [[email protected] tmp]$

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


    [[email protected] tmp]$ more Test.txt
    Fri Feb 17 13:41:23 MST 2012
    20120217


    date +%F >> $myFile

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


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

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

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

    [[email protected] tmp]$ echo $myFile
    Test_2012-02-17--14:16.txt
    [[email protected] tmp]$

    [[email protected] tmp]$ touch $myFile
    [[email protected] 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
    [[email protected] tmp]$








    [[email protected] tmp]$
Sign In or Register to comment.