Files लिखना
एक file लिखना एक notebook में लिखने जैसा है: एक arrow page erase करके fresh शुरू करता है, जबकि दो arrows नीचे नई lines add करते हैं।
In this page:
Syntax
echo "text" > file_name
echo "text" >> file_name
printf "format\n" arguments >> file_name
Files लिखना
एक file में लिखने के लिए redirection उपयोग होता है: echo "text" > file.txt इसे overwrite करता है, और >> append करता है। printf को भी ज़्यादा formatted output के लिए उसी तरह उपयोग किया जा सकता है।
Bash में कोई dedicated "write" command नहीं है — लिखना हमेशा output redirection के through ही होता है।
Note:
writes के एक batch की शुरुआत में एक बार
> उपयोग करें, फिर subsequent lines के लिए >> पर switch करें, ताकि हर बार file को re-truncate करने से बचा जा सके।उदाहरण: Writing Files
#!/bin/bash
echo "First line" > notes.txt
echo "Second line" >> notes.txt
printf "Third line with %s\n" "formatting" >> notes.txt
cat notes.txt
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
>>मतलब होने पर>उपयोग करना, जो file erase कर देता है।- एक directory में लिखना जो मौजूद नहीं है।
- एक command में same file को पढ़ना और लिखना।
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: