Skip to content

v-env/bash

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

class: center, middle , inverse, farsi

bash

اسکریپت نویسی bash

echo 'hello dudes!'

githubwebsite


class: center, middle , inverse, farsi

حلقه‌ها


class: farsi

دستور seq

  • دستور seq دنباله ای از اعداد را ایجاد می‌کند. مثلا برای اعداد ۱ تا ۵ می‌نویسیم
seq 1 5
1
2
3
4
5
  • این‌جوری می‌شه گام هم براش تعریف کرد که دوتا دو تا بره جلو مثلاً
seq 1 2 5
1
3
5

class: inverse, farsi

حلقهٔ for

for i in $( seq 1 5 )
do
  echo $i
done
1
2
3
4
5

class: inverse, farsi

تفاوت while و until

حلقهٔ while تا زمانی که شرط «درست باشه» ادامه پیدا می‌کنه

حلقهٔ until تا وقتی که شرط «درست بشه» ادامه پیدا می‌کنه،

  • یعنی قراره false باشه همیشه وقتی true شد اون موقع تموم می‌شه

class: inverse, farsi

تفاوت while و until

COUNTER=0
while [ $COUNTER -lt 5 ]; do
    echo counter is $COUNTER
    let COUNTER+=1 
done
counter is 0
counter is 1
counter is 2
counter is 3
counter is 4

class: inverse, farsi

تفاوت while و until

COUNTER=10
until [ $COUNTER -lt 5 ]; do
    echo counter is $COUNTER
    let COUNTER-=1 
done
counter is 10
counter is 9
counter is 8
counter is 7
counter is 6
counter is 5

class: center, middle , inverse, farsi

دستور‌های خط فرمان لینوکس


class: inverse, farsi

tr

  • فرض کنید فایل sample.txt با متن داخلی زیر را در اختیار داریم
cat ./sample.txt
April is the cruelest month, breeding
lilacs out of the dead land, mixing
memory and desire, stirring
dull roots with spring rain

class: inverse, farsi

tr

  • با دستور tr می‌تونیم یه سری پترن‌ها را به پترن‌های دیگه ترجمه کنیم
cat sample.txt |  tr aeoui AEOUI
AprIl Is thE crUElEst mOnth, brEEdIng
lIlAcs OUt Of thE dEAd lAnd, mIxIng
mEmOry And dEsIrE, stIrrIng
dUll rOOts wIth sprIng rAIn
  • اینجا، هر حرف صدا داری که با حروف کوچیک نوشته شده باشه را به حروف بزرگ تبدیل می‌کنیم

class: inverse, farsi

tr

  • می‌تونیم بدون cat هم از tr استفاده کنیم. اینجوری خروجی رو توی stdout می‌بینیم
tr aeoui AEOUI  < sample.txt
AprIl Is thE crUElEst mOnth, brEEdIng
lIlAcs OUt Of thE dEAd lAnd, mIxIng
mEmOry And dEsIrE, stIrrIng
dUll rOOts wIth sprIng rAIn

class: inverse, farsi

tr

  • یا همون دستور قبلی رو استفاده کنیم ولی خروجی رو توی یه فایل بنویسیم
tr aeoui AEOUI  < sample.txt > output.txt
cat output.txt
AprIl Is thE crUElEst mOnth, brEEdIng
lIlAcs OUt Of thE dEAd lAnd, mIxIng
mEmOry And dEsIrE, stIrrIng
dUll rOOts wIth sprIng rAIn

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • HTML 47.8%
  • CSS 37.8%
  • Shell 10.6%
  • Awk 3.8%