← Back to Bash Course | Chapter 1: Setup & Basics | Lesson 5 of 12

echo कमांड

echo आपके computer के लिए एक parrot जैसा है: आप जो भी इसे देते हैं, वह उसे screen पर वापस बोल देता है।

In this page:

  1. The echo Command
Syntax
bash
echo [-n] [-e] "text"

The echo Command

echo text को standard output पर print करता है, optionally एक newline के साथ। यह -n (कोई trailing newline नहीं) और -e (backslash escapes जैसे \n और \t interpret करना) जैसे flags support करता है। एक script से output produce करने का यह सबसे basic तरीका है।

Note: echo -e उपयोग करें जब आपको \n जैसे escape sequences की ज़रूरत हो जो असल में एक नई line बनाएं।

उदाहरण: The echo Command

bash
#!/bin/bash
echo "Hello, Bash!"
echo -n "No newline after this"
echo ""
echo -e "Line1\nLine2\tTabbed"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि echo "a\nb" दो lines print करेगा, जब Bash के echo को \n interpret करने के लिए -e चाहिए।
  2. एक variable unquoted छोड़ना, जैसे echo $name, इसलिए spaces और wildcard characters expand हो जाते हैं।
  3. यह भूल जाना कि echo -n (कोई newline नहीं) एक ही line पर रहने के लिए उपयोग होता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.