Red_Hat
EX300(23Q) · Question #16
Create a script on serverX called /root/random with following details. - When run as /root/random postconf, should bring the output as "postroll" - When run as /root/random postroll, should bring…
vim /root/random #!/bin/bash case $@ in postconf) echo "postroll" ;; postroll) echo "postconf" ;; *) echo "$0 postconf|postroll" >&2 ;; esac chmod +x /root/random
Bash Scripting and Automation
Question
- Create a script on serverX called /root/random with following details. - When run as /root/random postconf, should bring the output as "postroll" - When run as /root/random postroll, should bring the output as "postconf" - When run with any other argument or without argument, should bring the stderr as "/root/random postconf|postroll"
Explanation
vim /root/random #!/bin/bash case $@ in postconf) echo "postroll" ;; postroll) echo "postconf" ;; *) echo "$0 postconf|postroll" >&2 ;; esac
chmod +x /root/random
Topics
#bash scripting#conditional argument handling#stderr output#case statement
Community Discussion
No community discussion yet for this question.