English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

أمر echo في الشل

The echo command in Shell is similar to the echo command in PHP, both of which are used for string output. Command format:

echo string

You can use echo to implement more complex output format control.

1. Display ordinary strings:

echo "It is a test"

The double quotes can be omitted here, the following command has the same effect as the above example:

echo It is a test

2. Display escape characters

echo \

The result will be:

It is a test

يمكن أيضًا تجنب استخدام العلامات雙引

3. عرض المتغير

يقرأ الأمر read سطرًا من المدخل الاستاندارد، ويخصص قيمة كل حقل من هذا السطر لمتغير الشل

#!/bin/sh
read name 
echo "$name It is a test"

يتم حفظ الكود أعلاه كـ test.sh، ويتلقى المتغير name المدخلات من المدخل الاستاندارد، النتيجة ستكون:

[root@www ~]# sh test.sh
OK            # مدخلات استاندارد
OK It is a test  # مخرجات

4. عرض مع تغيير السطر

echo -e "OK! \n" # -e يفتح الترجمة
echo "It is a test"

نتيجة الإخراج:

OK!
It is a test

5. عرض بدون تغيير السطر

#!/bin/sh
echo -e "OK! \c" # -e يفتح الترجمة \c لا يغير السطر
echo "It is a test"

نتيجة الإخراج:

OK! It is a test

6. إعادة نتيجة إلى ملف

echo "It is a test" > myfile

7. عرض النص الأصلي، دون ترجمة أو استخراج المتغيرات (باستخدام العلامة التشديد)

echo '$name\"'

نتيجة الإخراج:

$name\"

8. عرض نتيجة تنفيذ الأمر

echo `date`

ملاحظة: يستخدم هنا العلامة العكسية للأسهم `, وليس العلامة التشديد '.

سيتم عرض التاريخ الحالي

Thu Jul 24 10:08:46 CST 2018