- कई command-line utilities short form options (
-f) और long form options (--force) को support करती हैं
- short form interactive उपयोग के लिए होते हैं; scripts में long form का उपयोग करने की सिफारिश की जाती है
- उदाहरण के लिए, terminal में आप
$ git switch -c my-new-branch टाइप करते हैं.
- release script में इसे इस तरह लिखा जाता है:
try shell.exec("git fetch origin --quiet", .{});
try shell.exec("git switch --create release-{today} origin/main", .{ .today = stdx.DateUTC.now() }, );
- long form options पाठक के लिए कहीं अधिक वर्णनात्मक होते हैं
1 टिप्पणियां
Hacker News टिप्पणी
मुझे लंबे options पसंद हैं, लेकिन जब POSIX commands को portable तरीके से call करना हो, तो short options ही एकमात्र विकल्प होते हैं। POSIX लंबे options को निर्दिष्ट नहीं करता
string interpolation और command execution को mix नहीं करना चाहिए
मैं इस बात से सहमत हूँ कि लंबे options इस्तेमाल करने चाहिए, लेकिन portability का ध्यान रखना होगा
सभी options के बाद और dynamic arguments से पहले
--का उपयोग करना न भूलेंcommand को call करने से पहले यह जाँचना चाहिए कि उसकी लंबाई ARG_MAX से अधिक तो नहीं है
grep --ignore-case --files-with-matches -- "hello" *.cCMD="grep --ignore-case --files-with-matches -- \"hello\" *.c"ARG_MAX=$(getconf ARG_MAX)CMD_LEN=${#CMD}if (( CMD_LEN > ARG_MAX )); thenecho "Error: Command length ($CMD_LEN) exceeds ARG_MAX ($ARG_MAX)." >&2exit 1fieval "$CMD"# चेतावनी, यह file names को evaluate करता हैमैं इस तरीके से सहमत हूँ। एक और फायदा यह है कि man page में option क्या करता है, इसे grep करना आसान हो जाता है
अगर आप script को दूसरे POSIX systems पर portable बनाना चाहते हैं, तो आपको short options का उपयोग करना पड़ सकता है
options को अलग-अलग lines में रखना चाहिए ताकि उन्हें track करना और git blame करना आसान हो
scripts लिखते समय यह बुनियादी नियमों में से एक है। जहाँ लंबे options संभव हों, उनका उपयोग करना चाहिए
long-form options पाठक के लिए कहीं अधिक descriptive होते हैं