কোনও কমান্ড সফলভাবে কাজ করেছে কি না তা পরীক্ষা করতে আপনি পূর্ববর্তী কমান্ডের দ্বারা প্রদত্ত রিটার্নের স্থিতি পরীক্ষা করতে পারেন$? :
echo $?
রিটার্নের স্থিতি 0মানে কমান্ডটি সাফল্যের সাথে সম্পন্ন হয়েছে, যখন একটি শূন্য-আউটপুট ( ত্রুটি কোড ) এর অর্থ হবে কিছু সমস্যা হয়েছে বা ত্রুটি রয়েছে এবং ত্রুটি কোড থেকে বিভাগটি জানা যাবে can লিনাক্স / সি ত্রুটি কোডের মধ্যে সংজ্ঞায়িত করা হয় /usr/include/asm-generic/errno-base.hএবং /usr/include/asm-generic/errno.h।
এছাড়াও ব্যাশে, .bashrcএকটি উপাধি সংজ্ঞা দেয় alertযা সমাপ্তির স্থিতি সহ অবহিত করতে ব্যবহার করা যেতে পারে। আপনাকে কমান্ড বা কমান্ড কম্বো সহ এইরূপটি উপনামটি সংযুক্ত করতে হবে:
some_command --some-switch; alert
মৃত্যুদন্ড কার্যকর করা শেষ কমান্ডের রিটার্ন স্থিতি~/.bashrc প্রদর্শন করতে আপনি আপনার ফাইলটিতে নিম্নলিখিত কোডের লাইনটি যুক্ত করতে পারেন ..
# show the return code of last command executed
PS1='${debian_chroot:+($debian_chroot)}\u@\h(lst ret. $(echo $?) ):\w\$ '
( ~/.bashrcআপনার পছন্দের টেক্সট এডিটরের সাহায্যে ফাইলটি খুলুন , এবং উপরের লাইনটি অনুলিপি করুন, ফাইলটিতে এটি আটকে দিন এবং সংরক্ষণ করুন the টার্মিনালের একটি নতুন উদাহরণ চালু করুন, এবং এটি কার্যকরভাবে করা উচিত Or এটি PS1নীচের চিত্রিত মত মত।)
একটু ডেমো:
hash@precise(lst ret. 0 ):~$ ls -sh someFileThatsNotThere
ls: cannot access someFileThatsNotThere: No such file or directory
hash@precise(lst ret. 2 ):~$
hash@precise(lst ret. 2 ):~$ aCommandThatsNot
aCommandThatsNot: command not found
hash@precise(lst ret. 127 ):~$
hash@precise(lst ret. 127 ):~$ echo "you should get a lst ret. 0, I believe the system has echo installed :)"
you should get a lst ret. 0, I believe the system has echo installed :)
hash@precise(lst ret. 0 ):~$
hash@precise(lst ret. 0 ):~$ sudo touch /tmp/someTestFile
[sudo] password for hash:
hash@precise(lst ret. 1 ):~$
hash@precise(lst ret. 1 ):~$ chown $USER:$USER /tmp/someTestFile
chown: changing ownership of `/tmp/someTestFile': Operation not permitted
PS1খালি খোলার সাথে :) .. আরও কিছুটা,
function showRetStat {
## line1: initiliazing retStat with the return status of the previous command
retStat=$?
## line2: Left padding the return status with spaces. If you prefer the unpadded one, you can just replace
# $retStatFtd in the lines initializing noErrStr and errStr among other possible ways.
retStatFtd=$(sed -e :a -e 's/^.\{1,2\}$/ &/;ta' <<< $retStat)
## lines3&4: Setting the strings to display for a successful and unsuccessful run of previous command
# which we are going to display with the prompt string. Change the strings to display text of your
# choice like you may set noErrStr="yippie!" , errStr="oopsie!" in place of what they're now.
noErrStr="retStat "$retStatFtd" :: PASS ^_^"
errStr="retStat "$retStatFtd" :: FAIL x_x"
## line5: Applying the logic and display the proper string at the prompt. Space padded number i.e. retStatFtd, here,
# worked in the logic, originally I intended to use this for the display while retStat in the conditional
# check; you could make the function one statement less if you want to.
echo "$([ $retStatFtd = 0 ] && echo "$noErrStr" || echo "$errStr")"
}
## Combining the function showRetStat into the prompt string.
PS1='${debian_chroot:+($debian_chroot)}\u@\h($(showRetStat)):\w\$ '
(আপনি আরও বেশি অভিনব করে তুলতে ফাংশনটি সংশোধন করতে পারেন, @ গ্রোনস্টাজ তার পোস্টে এমন কিছু করে))