А знаете ли вы, что в Bash есть особая переменная "$_" ? Из описания можно узнать, что в переменную "$_" помещается последний аргумент последней команды.
Что-то знакомое? Конечно, в Python есть примерно тоже самое.
Мы знаем, что дата первого релиза Bash (8 июня 1989) несколько раньше чем первый релиз Python (20 февраля 1991). Если учесть, что по задумке автора Python это агрегация самых успешных практик отовсюду, можно ли сказать что именно эта фишка к нему пришла из Bash? Ни подтверждения ни опровержения я пока не нашел.
Давайте просто считать это совпадением 😉
А как это может быть полезно в Bash?
Приведу простой пример, который оценят те, кто часто работает в терминале.
Допустим, нам надо создать директорию и зайти в неё. Что обычно делаем?
:~$ mkdir foldername
:~$ cd foldername
:~/foldername$
Как это сделать в одну команду?
:~$ mkdir foldername && cd foldername
:~/foldername$
Уже лучше, но хочется короче, без повторов. Вот тут и пригодится наша переменная. Напомню, что в неё сохраняется последний аргумент предыдущей команды.
:~$ mkdir foldername && cd $_
:~/foldername$
_________________
PS.
Символы "&&"" разделяют команды и означают, что требуется выполнить вторую команду только если первая завершилась успешно.
#linux#tricks
"We are living in unprecedented times, but with fortitude and resilience, we can and will stand in solidarity as one united Singapore – to beat this crisis and emerge stronger as a nation." -- DPM Heng Swee Keat
#SGTogether#SGUnited
Catch Mr Liang Eng Hwa’s LIVE interview on Capital 95.8FM Tonight, 6.30pm!
Join us in discussing the Budget, Digitalisation & Jobs and national issues! Also find out what our citizens have to say through feedback collected by REACH. Stay tuned!
#SGUnited#SGTogether
More: https://www.facebook.com/92744267226/posts/10157332345052227
As we approach the end of the Circuit Breaker, measures will be progressively lifted in three phases from 2 June. Many restrictions in place will continue in Phase 1.
#SGUnited#SGTogether.
The Government announced that there will be gradual easing of Circuit Breaker measures. What are the services that will resume operation? Find out here!
#SGUnited#SGTogether
In our compact city, planning for the many different land use needs is often like a balancing act. By working together, we can make future Singapore a space for our hopes and dreams.
We've just launched Phase 2 of the Long-Term Plan Review public engagement exercise - come share your ideas at: go.gov.sg/ltpr
#LTPR2021#SGTogether
💡What do you value more in shaping a liveable Singapore: a good transportation network, convenient access to amenities, greenery in the city or the other factors above?
We're calling for your views and ideas in our online poll for the Long-Term Plan Review. With your participation, we can develop long-term land use plans that will better meet your needs and aspirations as well as those of future generations!
Tell us more at: go.gov.sg/ltpr
#LTPR2021#SGTogether
📣 We just launched our public engagement for the Long-Term Plan Review (LTPR) today and are excited to develop plans for Singapore's next chapter with you over the next year!
The #LTPR2021 is the latest review of plans that will steward land resources not just for today's use but also for future generations over the next 50 years and beyond.
We'd love to hear your hopes and aspirations for the future to develop these long-term plans! Watch how long-term planning has shaped the everyday lives of fellow citizens as well as what they dream for our future city - and share your dreams with us in our online poll at go.gov.sg/ltpr
#SGTogether
Where there are wet and dark crevices, NEA’s Dengue Inspection Officer Marthandan will be there. Let him show you how he and his team spot and tackle mosquito breeding in the areas around you!
Join him in our #NEAOfficers Story Highlight on our Instagram profile (www.instagram.com/nea_sg)!
#SGUnited#SGTogether
It has been more than a year since COVID-19 happened. Many of us have had to adapt to new work situations and overcome the various challenges the pandemic brought with it.
Today, we salute all workers, especially the frontliners who have been working extra hard to keep us safe this past year.
Happy Labour Day! 💪🇸🇬
#SGUnited#SGTogether
This National Day, let us celebrate the Singapore spirit that has kept us going during the most challenging of times. It will continue to help us emerge stronger for the future.
Happy 56th Birthday, Singapore!
#TogetherOurSGSpirit#SGUnited#SGTogether