Edited, memorised or added to reading queue

on 17-Oct-2018 (Wed)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 3412319931660

Question
In python, you have dictionary, d = {'a':1, 'b':2}, how do you delete item with key 'a' from d, and get the value of 'a' returned, all in one command (and do it in safe way so None is returned if key 'a' does not exist)?
Answer
d.pop('a', None)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 3420068908300

Question
In linux, write simple bash script, using case statement to check for first command line argument, if it is --help or -h print "help", if it is --version or -v print "1.0", otherwise print "unkown choice".
Answer
case $1 in
    --help|-h)
        echo "help"
        ;;
    --version|-v)
        echo "1.0"
        ;;
    *)
        echo "unknown choice"
        ;;
esac
^^ note the esac at end
^^ note the ;; seperating each option statement
^^ note the ) that is each pattern matching condition, also note that the left ( is missing/optional
^^ note the * catch all glob/pattern for the final condition

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
ng files and expand an absolute path. 7.6 The case Statement The case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh <span>case $1 in --test|-t) echo "you used the --test option" exit 0 ;; --help|-h) echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 0 ;; --version|-v) echo "myprog.sh version 0.0.1" exit 0 ;; -*) echo "No such option $1" echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 1 ;; esac echo "You typed \"$1\" on the command-line" Above you can see that we are trying to process the first argument to a program. It can be one of several options, so using if statements wil







Flashcard 3420100627724

Question
In linux, write simple bash script that prints out all the command line arguments of the script no matter how many or few (e.g. if you run script test.sh as "./tests.sh one two three", it will print out "one\n two\n three")
Answer
#!/bin/bash
while [ "$1" != "" ]; do
    echo $1
    shift
done
^^ note the use of shift
^^ also note the "$1" in the conditional clause of while loop (line 2) wrapped in "", as this is needed for string comparison!!!


statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
d argument is: birds Now we need to loop through each argument and decide what to do with it. A script like for i in $1 $2 $3 $4 ; do <statments> done doesn't give us much flexibilty. The <span>shift keyword is meant to make things easier. It shifts up all the arguments by one place so that $1 gets the value of $2 , $2 gets the value of $3 , and so on. ( != tests that the "$1" is no







1. Zaciśnij zęby i powstrzymaj chęć natychmiastowego sprzeciwu!
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




2. Pomyśl o emocjach, jakie odczuwa dziecko. 3. Nazwij te emocje i wypowiedz zdanie, którym je określisz.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




So. Postgres user handling is Bloody Fucking Weird, and very VERY archaic in some places.

To begin with, Postgres users are not the same users as your computer. Except when you use peer authentication, which is default for "local" connections (in-machine).

With peer authentication, you need to have the same username inside the database as outside. So root cannot connect as postgres into the database.

Postgres also supports other kinds of authentication, for example trust, which basically says yessir, you're ok no matter who you say you are (not very good).

It also supports the ancient and untrustworthy ident protocol, that noone in their sane mind would ever use, and which was designed in the 80s/90s.

Then comes the slightly more modern authentications, md5.

md5 is basically a username & password combination for your database, where both the username and password are stored in the database system. Then it no longer matters who you are connecting as on the computer ( be it root, postgres, joedope).

This is the sane method, and you should use it.

By default, postgres might use it if you give it a hostname of localhost. ( -h localhost).

Then comes the pg_hba.conf file, which is an amazing hairy construct. It's basically a firewall file for your database system. It tells you which users & databases are allowed to connect from which systems, including your local machine.

Then, because ident wasn't stupid enough, they re-envisoned ident as a config file, allowing you to override the username and other combinations in a file on your machine. Don't use it. Really don't.

What you want to do is this:
- Ignore peer authentication for anything but the postgres user.
- Create a new admin user (createuser) with password.
- Add your new admin user to pg_hba.conf like this:

local all mysuperuser md5 
    statusnot read reprioritisations
    last reprioritisation on suggested re-reading day
    started reading on finished reading on

    Cannot get into shell using psql command. : PostgreSQL
    Your? Do you enter your shell account password? Do you even have "user" account *in database *? permalink embed save parent give gold [–]Darkmere 1 point2 points3 points 1 year ago (0 children) <span>So. Postgres user handling is Bloody Fucking Weird, and very VERY archaic in some places. To begin with, Postgres users are not the same users as your computer. Except when you use peer authentication, which is default for "local" connections (in-machine). With peer authentication, you need to have the same username inside the database as outside. So root cannot connect as postgres into the database. Postgres also supports other kinds of authentication, for example trust, which basically says yessir, you're ok no matter who you say you are (not very good). It also supports the ancient and untrustworthy ident protocol, that noone in their sane mind would ever use, and which was designed in the 80s/90s. Then comes the slightly more modern authentications, md5. md5 is basically a username & password combination for your database, where both the username and password are stored in the database system. Then it no longer matters who you are connecting as on the computer ( be it root, postgres, joedope). This is the sane method, and you should use it. By default, postgres might use it if you give it a hostname of localhost. ( -h localhost). Then comes the pg_hba.conf file, which is an amazing hairy construct. It's basically a firewall file for your database system. It tells you which users & databases are allowed to connect from which systems, including your local machine. Then, because ident wasn't stupid enough, they re-envisoned ident as a config file, allowing you to override the username and other combinations in a file on your machine. Don't use it. Really don't. What you want to do is this: - Ignore peer authentication for anything but the postgres user. - Create a new admin user (createuser) with password. - Add your new admin user to pg_hba.conf like this: local all mysuperuser md5 permalink embed save give gold about blog about advertising careers help site rules Reddit help center wiki reddiquette mod guidelines contact us apps & tools Reddit for iPhone Redd




    #has-images

    “光”跑的这么快,它的速度是如何测量的?



      想必大家在日常生活中都有这样的经验,在雷雨天气,我们总是先看到闪电的光,然后过了好久才听到轰隆隆的雷声。这其中的原因也不难理解,那就是因为光的速度比声音的速度快多了。




      空气中声音的速度大概是340m/s,一马赫的速度,就是指的是声音在空气中的速度。对于光,它的速度似乎是无限的,在日常生活中,光似乎能瞬间从一个地点到另一个地点,例如我们打开手电筒,几乎就在同时我们就看到了手电筒发出的光传播的很远。其实光的速度也是有限的,只不过非常大。

      光在空气中的速度约为3*10^8 m/s。这个速度有多快呢?光在一秒钟内前进的距离大约就可以绕地球赤道7圈半,也就是说,几乎一眨眼的时间光就可以毫不费力的环游世界。从地球到月球的距离约为38万公里,光打个来回也仅仅需要两秒多(事实上,地球和月球之间的准确距离就是计算激光来回所花费时间得到的)。而人类在1969年第一次登上月球,花费了三天多的时间才到达月球,由此可见光速有多快。光速是目前人类已知速度的上限,没有什么东西能运动的比光速还快。既然光速这么快,那科学家们是如何知道光速的准确数值的呢?


    激光测距



      光速测量史

      人类历史上首次测量光速是在1676年。当时丹麦天文学家奥勒·罗默通过研究木星的卫星木卫一发现光速是有限的,并不是无限的,并由此估计出了光速的值。他估算的过程如下图所示:


    光速的估量



      其中的大环是地球绕太阳的轨道,小环是木卫一绕木星的轨道。当地球远离木星(从L到K)和接近木星(从F到G)时,木卫一从木星的阴影里(C到D)出来的时间会产生变化,从这个变化可以就知道光速是有限的,再加上木卫一绕木星的公转周期和地球的公转周期以及公转速度,就可以估算出光速了。从这中方法估计出的光速误差很大,约为2.2x10^8m/s, 比实际值小26%。

      在1728年,英国天文学家詹姆斯·布拉德利进一步提高了光速的准确度。他所使用的是恒星的光行差。光行差如下图所示


    光行差示意图



      光行差,简单的来说就是地球的运动,会使恒星的方位产生变化。举例来说就是,假设在无风的天气里下雨,雨滴会垂直下落到你的身上,当你以一定的速度奔跑是,雨滴就会以另外一个角度落到你身上,不再垂直。结合这个角度的改变和你的速度,就可以估计出雨滴下落的速度。同样使用恒星光行差,结合地球的公转速度和恒星角度的变化,就可以估算出光速。使用这种方法估算出的光速约为3.01*10^8 m/s,误差仅仅为0.4%。

      提升光速测量精度

      首次准确在地球上,而不是依靠天体运动来测量光速的实验是在1849年由法国物理学家阿曼德·斐索实行的,他使用的方法叫做齿轮测速法。


    齿轮法测光速



      这个方法的关键在于齿轮的转速,齿轮从很低的转速开始逐渐提速,在转速提升到某一关键速度的时候,齿轮转过两个齿的角度时,光线刚好从远处的镜子里折回。这样根据两齿之间的角度以及齿轮的转速,镜子的距离就可以计算出光速的大小。假设齿轮的转速刚好是,齿轮一共有N个齿,远处的镜子距离观察者L。那么光速。




      1849年阿曼德·斐索用这种装置测出的光速是3.15*10^8m/s,误差为5%,但是随后,法国科学家莱昂·傅科(就是用傅科摆演示地球自转的那个科学家),提高了这个装置的精确度,用旋转镜面代替了旋转的之轮,测出了2.98*10^8m/s的光速值,误差缩小到了0.5%。 旋转齿轮法和旋转镜面法对于光速的准确测量产生了很深远的影响,这种方法简单易行,结果很有说服力。直到1926年,这种方法都一直被当做测量光速的首选,精度一直提高到了0.001%左右。

      齿轮测速法较为精确并且可信地测出了光速的值。之后不久(1861-1862年)就出现了伟大的麦克斯韦(1831-1879,苏格兰物理学家),给出了麦克斯韦方程组,完美的描述了电磁波的运动,他从方程组中得出电磁波的速度约为




      非常接近当时光速的值,于是他大胆的猜测光就是一种特殊频率的电磁波。后来的实验确实证明了他的猜测。


    史上最伟大的物理学家之一—詹姆斯·克拉克·麦克斯韦



      当知道光是电磁波之后,我们就可以从另外一种方式得到准确的光速,那就是通过测量(真空磁导率)和(真空介电常数)来计算光速,也就是上面提到的




      在1907年,美国科学家爱德华(Edward Bennett Rosa)和多尔西(N.E。 Dorsey)通过这种方法给出了当时最精确的光速值2.99788*10^8m/s,误差仅仅为0.003%。。

      20世纪50年代以后,随着电子工业技术的发展, 各种测量光速的新技术相继出现,例如谐振腔法(1950年),无线电干涉法(1958年),激光干涉法(1972年)等。下面我们一一介绍。

      谐振腔法主要依据的物理原理就是光也是电磁波,因为任意波长的电磁波具有相同

    ...
    statusnot read reprioritisations
    last reprioritisation on suggested re-reading day
    started reading on finished reading on

    [Ò»ÄÉÌìÎÄ]¡°¹â¡±ÅܵÄÕâô¿ì£¬ËüµÄËÙ¶ÈÊÇÈçºÎ²âÁ¿µÄ£¿ - ¼¼ÐgӑՓ…^ | ²ÝÁñÉç…^ - t66y.com
    最高、出款速度最快、体验效果最好、千万彩民、购彩首选!首冲有豪礼、1元存款、提现1分钟到账、多种玩法、超高赔率! yilecai.cc [凤凰娱乐:1156.COM] 十年凤凰 一如既往! 老品牌,值得信赖!1元即可存取款,美女荷官在线发牌,百家乐,牛牛,AV捕鱼王,上万款老虎机游戏任你玩。下载APP送18元,赢到100可以直接提现。FHYL.COM fhyl.com 一纳 全都收纳 <span>“光”跑的这么快,它的速度是如何测量的? 想必大家在日常生活中都有这样的经验,在雷雨天气,我们总是先看到闪电的光,然后过了好久才听到轰隆隆的雷声。这其中的原因也不难理解,那就是因为光的速度比声音的速度快多了。 空气中声音的速度大概是340m/s,一马赫的速度,就是指的是声音在空气中的速度。对于光,它的速度似乎是无限的,在日常生活中,光似乎能瞬间从一个地点到另一个地点,例如我们打开手电筒,几乎就在同时我们就看到了手电筒发出的光传播的很远。其实光的速度也是有限的,只不过非常大。 光在空气中的速度约为3*10^8 m/s。这个速度有多快呢?光在一秒钟内前进的距离大约就可以绕地球赤道7圈半,也就是说,几乎一眨眼的时间光就可以毫不费力的环游世界。从地球到月球的距离约为38万公里,光打个来回也仅仅需要两秒多(事实上,地球和月球之间的准确距离就是计算激光来回所花费时间得到的)。而人类在1969年第一次登上月球,花费了三天多的时间才到达月球,由此可见光速有多快。光速是目前人类已知速度的上限,没有什么东西能运动的比光速还快。既然光速这么快,那科学家们是如何知道光速的准确数值的呢? 激光测距 光速测量史 人类历史上首次测量光速是在1676年。当时丹麦天文学家奥勒·罗默通过研究木星的卫星木卫一发现光速是有限的,并不是无限的,并由此估计出了光速的值。他估算的过程如下图所示: 光速的估量 其中的大环是地球绕太阳的轨道,小环是木卫一绕木星的轨道。当地球远离木星(从L到K)和接近木星(从F到G)时,木卫一从木星的阴影里(C到D)出来的时间会产生变化,从这个变化可以就知道光速是有限的,再加上木卫一绕木星的公转周期和地球的公转周期以及公转速度,就可以估算出光速了。从这中方法估计出的光速误差很大,约为2.2x10^8m/s, 比实际值小26%。 在1728年,英国天文学家詹姆斯·布拉德利进一步提高了光速的准确度。他所使用的是恒星的光行差。光行差如下图所示 光行差示意图 光行差,简单的来说就是地球的运动,会使恒星的方位产生变化。举例来说就是,假设在无风的天气里下雨,雨滴会垂直下落到你的身上,当你以一定的速度奔跑是,雨滴就会以另外一个角度落到你身上,不再垂直。结合这个角度的改变和你的速度,就可以估计出雨滴下落的速度。同样使用恒星光行差,结合地球的公转速度和恒星角度的变化,就可以估算出光速。使用这种方法估算出的光速约为3.01*10^8 m/s,误差仅仅为0.4%。 提升光速测量精度 首次准确在地球上,而不是依靠天体运动来测量光速的实验是在1849年由法国物理学家阿曼德·斐索实行的,他使用的方法叫做齿轮测速法。 齿轮法测光速 这个方法的关键在于齿轮的转速,齿轮从很低的转速开始逐渐提速,在转速提升到某一关键速度的时候,齿轮转过两个齿的角度时,光线刚好从远处的镜子里折回。这样根据两齿之间的角度以及齿轮的转速,镜子的距离就可以计算出光速的大小。假设齿轮的转速刚好是,齿轮一共有N个齿,远处的镜子距离观察者L。那么光速。 1849年阿曼德·斐索用这种装置测出的光速是3.15*10^8m/s,误差为5%,但是随后,法国科学家莱昂·傅科(就是用傅科摆演示地球自转的那个科学家),提高了这个装置的精确度,用旋转镜面代替了旋转的之轮,测出了2.98*10^8m/s的光速值,误差缩小到了0.5%。 旋转齿轮法和旋转镜面法对于光速的准确测量产生了很深远的影响,这种方法简单易行,结果很有说服力。直到1926年,这种方法都一直被当做测量光速的首选,精度一直提高到了0.001%左右。 齿轮测速法较为精确并且可信地测出了光速的值。之后不久(1861-1862年)就出现了伟大的麦克斯韦(1831-1879,苏格兰物理学家),给出了麦克斯韦方程组,完美的描述了电磁波的运动,他从方程组中得出电磁波的速度约为 非常接近当时光速的值,于是他大胆的猜测光就是一种特殊频率的电磁波。后来的实验确实证明了他的猜测。 史上最伟大的物理学家之一—詹姆斯·克拉克·麦克斯韦 当知道光是电磁波之后,我们就可以从另外一种方式得到准确的光速,那就是通过测量(真空磁导率)和(真空介电常数)来计算光速,也就是上面提到的 在1907年,美国科学家爱德华(Edward Bennett Rosa)和多尔西(N.E。 Dorsey)通过这种方法给出了当时最精确的光速值2.99788*10^8m/s,误差仅仅为0.003%。。 20世纪50年代以后,随着电子工业技术的发展, 各种测量光速的新技术相继出现,例如谐振腔法(1950年),无线电干涉法(1958年),激光干涉法(1972年)等。下面我们一一介绍。 谐振腔法主要依据的物理原理就是光也是电磁波,因为任意波长的电磁波具有相同的速度,而电磁波的速度和它的波长和频率之间存在如下的关系: 速度=波长*频率。谐振腔法通过腔的尺寸可以很准确计算出里面电磁波的波长,而电磁波的频率又是已知的,因此,可以直接用上述公式计算出光的速度(或者说电磁波的速度)。 最后一种要说的就是激光干涉法了。目前各种资料查到的光速的值 299792458m/s,是通过激光干涉法测量出来的。无线电干涉和激光干涉本质上是一样的,因为它们都使用的是电磁波,只是波长不相同而已。因此我们只介绍激光干涉法。 想象一下水波,如下图所示,当两个水波相遇时,会产生干涉。当波峰和波峰(或波谷和波谷)相遇时,产生相加干涉,当波峰和波谷相遇时,会产生相消干涉。同样的道理对于光或者激光也是成立的。 水波干涉和波峰波谷示意图 激光干涉条纹 激光是一种高度相干的光,因此很适合用于进行干涉。从激光器发出的光的频率是已知的,精度可以达到10^-9赫兹 左右,波长的测量是通过法布里-珀罗干涉仪测量并和基准波长86-氪605nm的光谱线进行比较得到的,精度也可以达到10^-9m左右。由于激光干涉对于波长的要求非常的高,产生的干涉条纹和激光的波长密切相关,因此通过干涉条纹可以十分准确的计算出激光的波长。有了激光的频率和波长,就可以计算出光速了:光速=频率*波长。 1972年通过激光干涉法测出的光速值是299792.4562±0.0011m/s, 这时当时能达到的最高的精度了,因为当时米的定义是通过86-氪605nm的光谱线给出的,它的精度限制了光速精度的进一步提高。 不久后的1983年,国际计量大会直接规定光速的值为299792458m/s, 并且反过来用光速重新定义了米。也就是说现在的光速值是给定的,不会再改变了,精度也不会再继续提高了,因为它已经成了“米”这个基本单位的基准。所谓的基准,就是指“米”这个单位的最高精度是由光速的值给出的,因为光速值具有很好的稳定性和重复性。 从光速测量的历史可以看出,科学的进步并不是一蹴而就的,有时候需要好几代科学家的不懈努力才能实现。光速测量精度的不断提高,到现在成了一个确定的值,这对于物理学的发展来说十分重要。因为光速是物理中一个重要的常数,著名的质能方程 E=mc^2, 狭义相对论中的“尺缩钟慢”效应,广义相对论中的引力波,时空弯曲等等,都和光速密切相关。 每日天文一图 NGC 1672:哈勃望远镜拍摄的棒旋星系 许多旋涡星系都有个横跨其中央的棒状核心。甚至我们的银河系也被认为拥有一个不大的中央棒。以上这幅由轨道上的哈勃太空望远镜所拍摄的壮观细致特征影像呈现了显著的棒旋星系NGC 1672。在这幅影像中,还可见黑暗的丝状尘埃带,明亮蓝色恒星聚成的年轻星团,炽热氢气构成的红色发射星云,一个横跨星系中心、由恒星组成的明亮长棒




    Flashcard 3433536556300

    Question
    In linux, in bash scripting, what does $0 mean (give an example to illustrate your knowledge)?
    Answer
    $0 references the name of the bash program/script itself (for example, if you run the script as "./test.sh one two", $0 is ./test.sh

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    og2.sh "$@" fi $0 means the name of the program itself and not any command-line argument. It is the command used to invoke the current program. In the above cases, it is ./myprog.sh . Note that <span>$0 is immune to shift operations. 7.10 Single Forward Quote Notation Single forward quotes ' protect the enclosed text from the shell. In other words, you can place any odd characters insi







    Flashcard 3433539177740

    Question
    In linux, in bash scripting if you have script that you run as: ./test.sh one two three
    And the above test script has line: echo $0
    What is the output?
    Answer
    ./test.sh

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    rsion 0.0.3" exit 0 ;; -*) echo "Error: no such option $1" usage exit 1 ;; esac shift done myprog.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments: <span>$@ and $0 Whereas $1 , $2 , $3 , etc. expand to the individual arguments passed to the program, $@ expands to all arguments. This behavior is useful for passing all remaining arguments ont







    Flashcard 3433542323468

    Question
    In linux, in bash scripting if you have script that you run as: ./test.sh one two three
    And the above test script has line: echo $@
    What is the output?
    Answer
    one two three

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    rsion 0.0.3" exit 0 ;; -*) echo "Error: no such option $1" usage exit 1 ;; esac shift done myprog.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments: <span>$@ and $0 Whereas $1 , $2 , $3 , etc. expand to the individual arguments passed to the program, $@ expands to all arguments. This behavior is useful for passing all remaining arguments onto a sec







    Flashcard 3433545469196

    Question
    In linux, in bash scripting, what does $@ mean (give an example to illustrate your knowledge)?
    Answer
    it expands all the command line variables for example (not including $0): if you have command: ./test.sh one two three, $@ would be: one two three.
    ^^note: it is useful in cases where you want to give the remaining command-line args to another command, after perhaps removing some via "shift"

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    g.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments: $@ and $0 Whereas $1 , $2 , $3 , etc. expand to the individual arguments passed to the program, <span>$@ expands to all arguments. This behavior is useful for passing all remaining arguments onto a second command. For instance, if test "$1" = "--special" ; then shift myprog2.sh "$@" fi $0







    Flashcard 3433548614924

    Question
    In linux, in bash scripting, [...] is different that $1, $2, $3, etc, in that it is not changed by the shift statement
    Answer
    $0

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    program, $@ expands to all arguments. This behavior is useful for passing all remaining arguments onto a second command. For instance, if test "$1" = "--special" ; then shift myprog2.sh "$@" fi <span>$0 means the name of the program itself and not any command-line argument. It is the command used to invoke the current program. In the above cases, it is ./myprog.sh . Note that $0 is imm







    Flashcard 3433551760652

    Question
    In linux, in bash scripting, the purpose of the [...] charactor is to protect the enclosed text from the shell.
    Answer
    '
    ^^ single quote

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    t is the command used to invoke the current program. In the above cases, it is ./myprog.sh . Note that $0 is immune to shift operations. 7.10 Single Forward Quote Notation Single forward quotes <span>' protect the enclosed text from the shell. In other words, you can place any odd characters inside forward quotes, and the shell will treat them literally and reproduce your text exactly. For instance, you may want to echo an a







    Flashcard 3433554906380

    Question
    In linux, in bash scripting, the purpose of the ' charactor (single quote charactor) is to protect the enclosed text from [...] .
    Answer
    the shell
    ^^ e.g. if you want to do echo '$1000' and not have to escape the special shell meaning of $

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    t is the command used to invoke the current program. In the above cases, it is ./myprog.sh . Note that $0 is immune to shift operations. 7.10 Single Forward Quote Notation Single forward quotes <span>' protect the enclosed text from the shell. In other words, you can place any odd characters inside forward quotes, and the shell will treat them literally and reproduce your text exactly. For instance, you may want to echo an ac







    Flashcard 3433558052108

    Question
    In linux, in bash scripting, the purpose of the [...] charactor is to protect the enclosed text against whitespace seperation.
    Answer
    "
    ^^ double quotes

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    costs $1000' instead of echo "costs $1000" . 7.11 Double-Quote Notation Double quotes " have the opposite sense of single quotes. They allow all shell interpretations to take place inside them. <span>The reason they are used at all is only to group text containing whitespace into a single word, because the shell will usually break up text along whitespace boundaries. Try, for i in "henry john mary sue" ; do echo "$i is a person" done compared to for i in henr







    Flashcard 3433561197836

    Question
    In linux, write simple bash scripts (with just one line) that just prints out following line:
    The cost is $1000
    Answer
    echo 'the cost is $1000'
    ^^ note the wrapping around single quotes
    ^^ can also be done as: echo "the cost is \$1000", but the first option of single quote wrapping is cleaner/better

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    at them literally and reproduce your text exactly. For instance, you may want to echo an actual $ to the screen to produce an output like costs $1000 . You can use echo 'costs $1000' instead of <span>echo "costs $1000" . 7.11 Double-Quote Notation Double quotes " have the opposite sense of single quotes. They allow all shell interpretations to take place inside them. The reason they are used at all is







    Flashcard 3433564343564

    Question
    In linux, in bash scripting, command expansion syntax can be either, for example: echo $(ls) , or equavilantly: echo [...]
    Answer
    `ls`
    ^^ note the use of the single backward quotes around ls

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    n factorial 20 and see the output. If we want to assign the output to a variable, we can do this with X=`factorial 20` . Note that another notation which gives the effect of a backward quote is <span>$( command ) , which is identical to ` command ` . Here, I will always use the older backward quote style. Next: 8. Streams and sed Up: rute Previous: 6. Editing Text Files Contents <span>







    Flashcard 3433569062156

    Question
    In linux, in bash scripting, expression expansion syntax can be either, for example: echo $[2*2] , or equavilantly: echo [...]
    Answer
    `expr 2 '*' 2`
    ^^ note the use of single backwards quotes wrapped around statement
    ^^ note the escaping of the shell special char * around single normal quotes, escaping of * can also be done via: \*

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    7. Shell Scripting
    do A=`expr $A '*' $N` N=`expr $N - 1` done echo $A } We can see that the square braces used further above can actually suffice for most of the times where we would like to use expr . (However, <span>$[] notation is an extension of the GNU shells and is not a standard feature on all varients of UNIX.) We can now run factorial 20 and see the output. If we want to assign the output to a v







    Można zaakceptować wszystkie uczucia. Należy ograniczyć niektóre działania!
    statusnot read reprioritisations
    last reprioritisation on suggested re-reading day
    started reading on finished reading on

    pdf

    cannot see any pdfs




    Flashcard 3433740766476

    Question
    In Linux, how do you save the output of running "ls" to a file, called "ls.output", that does NOT already exist.
    Answer
    ls > ls.output
    ^^ note if ls.output already existed, it would be overwritten with output of ls.

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    hat contain the word GNU and one line that contains the word GNU as well as the word Linux . Then run grep GNU myfile.txt . The result is printed to stdout as usual. Now try grep GNU myfile.txt <span>> gnu_lines.txt . What is happening here is that the output of the grep command is being redirected into a file. The > gnu_lines.txt tells the shell to create a new file gnu_lines.txt







    Flashcard 3433745222924

    Question
    In Linux, how do you append the output of the command, ls, to the end of an already existing file called outputs.txt?
    Answer
    ls >> output.txt
    ^^ note the double >> for append!

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    [Shortened to zero length.] Now suppose you want to append further output to this file. Using >> instead of > does not truncate the file, but appends output to it. Try echo "morestuff" <span>>> gnu_lines.txt then view the contents of gnu_lines.txt . 8.3 Piping Using | Notation The real power of pipes is realized when one program can read from the output of another program. Con







    Flashcard 3433748368652

    Question
    In linux, you have file called test.txt, how do you just print out the lines from test.txt that have both the words 'GNU' AND the word 'Test" (in any order)?
    Answer
    grep -w 'GNU' test.txt | grep -w 'Test'
    ^^ note the use of two greps in a pipe to do the AND filtering.

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    he second grep command scans that data for lines with the word Linux in them. grep is often used this way as a filter [Something that screens data.] and can be used multiple times, for example, <span>grep L myfile.txt | grep i | grep n | grep u | grep x The < character redirects the contents of a file in place of stdin. In other words, the contents of a file replace what would normally come from a keyboard. Try grep GNU < gnu_lin







    Flashcard 3433751514380

    Question
    In Linux, call the grep command to search for word 'hello' and read from the file test.txt, instad of from stdin (i.e. use file redirection syntax).
    Answer
    grep -w 'hello' < test.txt
    ^^ note the use of the < char to read input from a file instead of from stdin (which grep reads from when no file is supplied).

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    i | grep n | grep u | grep x The < character redirects the contents of a file in place of stdin. In other words, the contents of a file replace what would normally come from a keyboard. Try <span>grep GNU < gnu_lines.txt 8.4 A Complex Piping Example In Chapter 5 we used grep on a dictionary to demonstrate regular expressions. This is how a dictionary of words can be created (your dictionary might be und







    Flashcard 3433754660108

    Question
    In linux, if you run the command "ls exiting_file.txt non-existing_file.txt", and the output on the prompt is:
    ls: cannot access non-existing_file.txt: No such file or directory
    -rw-rw-r-- 1 kevin kevin 6 Oct 17 16:03 existing_file.txt

    Reissue the ls command above such that you capture all of the above output (i.e. the error message and the output line) to a file called "output.txt"?

    Answer

    ls existing_file.txt non-existing_file.txt > output.txt 2>&1
    ^^ note: the 2>&1, means redirect stderr (2) to stdout(1) and since things are executed from right to left this must be declared before the "> output.txt" part
    ^^ note: the first >, is same as 1> which means redirect stdout (i.e. 1) to output.txt

    ^^^ shorthand is just: ls existing_file.txt non-existing_file.txt &> output.txt


    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    ipe x into pipe y. Redirection is specified from right to left on the command-line. Hence, the above command means to mix stderr into stdout and then to redirect stdout to the file A . Finally, <span>ls existing_file non-existing_file 2>A 1>&2 cat A We notice that this has the same effect, except that here we are doing the reverse: redirecting stdout into stderr and then redirecting stderr into a file A . To see what happens







    Flashcard 3433757805836

    Question
    ln linux, when you issue command:
    ls existing_file.txt non-existing_file.txt > output.txt 2>&1
    the 2>&1, means redirect [...] to [...]
    Answer
    stderr to stdout
    ^^ above reads stardard error to standard output

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    riptor 1 when you don't specify a file descriptor. Now A contains the stdout output, while the error message has been redirected to the screen. Now try ls existing_file non-existing_file 1>A <span>2>&1 cat A Now A contains both the error message and the normal output. The >& is called a redirection operator. x >& y tells the shell to write pipe x into pipe y. Redirection







    Flashcard 3433760951564

    Question
    ln linux, when you issue command:
    ls existing_file.txt non-existing_file.txt > output.txt 2>&1
    Why does it matter what order you place the "> output.txt" part vs the "2>&1" part in (i.e. why can't you reverse the order of these parts)?
    Answer
    Because the order of redirection execution is done right to left.
    In other words, 2>&1 is done first. i.e. send stderr to stdout, then send stdout, 1> or just >, (which now combines stderr) to output.txt. Putting them in reverse would send stdout to output.txt (without combining it with stderr) then just combine stderr with stdout (which would just be seen in the prompt only)

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    1>A 2>&1 cat A Now A contains both the error message and the normal output. The >& is called a redirection operator. x >& y tells the shell to write pipe x into pipe y. <span>Redirection is specified from right to left on the command-line. Hence, the above command means to mix stderr into stdout and then to redirect stdout to the file A . Finally, ls existing_file non-existing_file 2>A 1>&2







    Flashcard 3433764097292

    Question
    In linux, sed stands for [...] [...]
    Answer
    stream editor

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    x stderr and stdout because the redirection to A came first. 8.6 Using sed to Edit Streams ed used to be the standard text editor for UNIX. It is cryptic to use but is compact and programmable. <span>sed stands for stream editor and is the only incarnation of ed that is commonly used today. sed allows editing of files non-interactively. In the way that grep can search for words and filter lines of text, sed can







    Flashcard 3433767243020

    Question
    In linux, what is the most common usage of sed?
    Answer
    To search for and replace words in a stream (it does so by parsing a file, or stdin, one line at a time and outputing to stdout)

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    arch-replace operations and insert and delete lines into text files. sed is one of those programs with no man page to speak of. Do info sed to see sed 's comprehensive info pages with examples. <span>The most common usage of sed is to replace words in a stream with alternative words. sed reads from stdin and writes to stdout. Like grep , it is line buffered, which means that it reads one line in at a time and then writes that line out again after performing whateve







    Flashcard 3433770388748

    Question
    In linux, sed, just like grep, reads from stdin (or a file) and writes to [...]
    Answer
    stdout

    statusnot learnedmeasured difficulty37% [default]last interval [days]               
    repetition number in this series0memorised on               scheduled repetition               
    scheduled repetition interval               last repetition or drill
    8. Streams and sed -- The Stream Editor
    ose programs with no man page to speak of. Do info sed to see sed 's comprehensive info pages with examples. The most common usage of sed is to replace words in a stream with alternative words. <span>sed reads from stdin and writes to stdout. Like grep , it is line buffered, which means that it reads one line in at a time and then writes that line out again after performing whatever editing operations. Replacements are typi







    The packet filtering mechanism provided by iptables is organized into three different kinds of structures: tables, chains and targets. Simply put, a table is something that allows you to process packets in specific ways. The default table is the filter table, although there are other tables too.

    Again, these tables have chains attached to them. These chains allow you to inspect traffic at various points, such as when they just arrive on the network interface or just before they’re handed over to a process. You can add rules to them match specific packets — such as TCP packets going to port 80 — and associate it with a target. A target decides the fate of a packet, such as allowing or rejecting it.

    When a packet arrives (or leaves, depending on the chain), iptables matches it against rules in these chains one-by-one. When it finds a match, it jumps onto the target and performs the action associated with it. If it doesn’t find a match with any of the rules, it simply does what the default policy of the chain tells it to. The default policy is also a target. By default, all chains have a default policy of allowing packets.

    statusnot read reprioritisations
    last reprioritisation on suggested re-reading day
    started reading on finished reading on

    An In-Depth Guide to iptables, the Linux Firewall - Boolean World
    functionality in netfilter. However, to keep this article simple, we won’t make a distinction between iptables and netfilter in this article, and simply refer to the entire thing as “iptables”. <span>The packet filtering mechanism provided by iptables is organized into three different kinds of structures: tables, chains and targets. Simply put, a table is something that allows you to process packets in specific ways. The default table is the filter table, although there are other tables too. Again, these tables have chains attached to them. These chains allow you to inspect traffic at various points, such as when they just arrive on the network interface or just before they’re handed over to a process. You can add rules to them match specific packets — such as TCP packets going to port 80 — and associate it with a target. A target decides the fate of a packet, such as allowing or rejecting it. When a packet arrives (or leaves, depending on the chain), iptables matches it against rules in these chains one-by-one. When it finds a match, it jumps onto the target and performs the action associated with it. If it doesn’t find a match with any of the rules, it simply does what the default policy of the chain tells it to. The default policy is also a target. By default, all chains have a default policy of allowing packets. Now, we’re going to take a deeper look into each of these structures. Tables As we’ve mentioned previously, tables allow you to do very specific things with packets. On a modern Linux d




    Lookups occur on the local computer, not on the remote computer. They are executed with in the directory containing the role or play, as opposed to local tasks which are executed with the directory of the executed script. You can pass wantlist=True to lookups to use in jinja2 template “for” loops. Lookups are an advanced feature. You should have a good working knowledge of Ansible plays before incorporating them.
    statusnot read reprioritisations
    last reprioritisation on suggested re-reading day
    started reading on finished reading on

    Lookups — Ansible Documentation
    ol machine, and can include reading the filesystem as well as contacting external datastores and services. This data is then made available using the standard templating system in Ansible. Note <span>Lookups occur on the local computer, not on the remote computer. They are executed with in the directory containing the role or play, as opposed to local tasks which are executed with the directory of the executed script. You can pass wantlist=True to lookups to use in jinja2 template “for” loops. Lookups are an advanced feature. You should have a good working knowledge of Ansible plays before incorporating them. Warning Some lookups pass arguments to a shell. When using variables from a remote/untrusted source, use the |quote filter to ensure safe usage. Topics Lookups Lookups and loops Lookups