← Back to Bash Course | Chapter 3: Control Flow | Lesson 7 of 14

Pipes का उपयोग

एक pipe एक bucket line जैसा है जहां एक kid अपने पास जो है वह अगले kid को पास करता है। हर command अपना छोटा काम करता है और result आगे सौंपता है।

In this page:

  1. Pipes
Syntax
bash
command1 | command2 | command3

Pipes

Pipe operator | एक command के standard output को सीधे अगले के standard input से connect करता है, आपको छोटे commands को एक data-processing pipeline में chain करने देते हुए।

Bash दोनों commands को concurrently चलाता है, उनके बीच data streaming करते हुए। Pipelines shell scripting के सबसे powerful और idiomatic features में से एक हैं।

Note: कई pipes को एक साथ chain करें, जैसे cmd1 | cmd2 | cmd3, एक line में एक multi-step data pipeline बनाने के लिए।

उदाहरण: Pipes

bash
#!/bin/bash
printf "banana\napple\ncherry\n" | sort

echo "---"

printf "a\nb\nc\nd\n" | wc -l
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. यह उम्मीद करना कि एक pipe error messages (stderr) भेजेगा, जब सिर्फ standard output इससे गुजरता है।
  2. एक pipe के end पर एक while read loop के अंदर variables set करना और loop के बाद उनकी उम्मीद करना, क्योंकि यह एक subshell में चलता है।
  3. cat file | grep x उपयोग करना जहां grep x file काफी है।

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.