{"id":6200,"date":"2018-12-27T12:33:37","date_gmt":"2018-12-27T12:33:37","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=6200"},"modified":"2018-12-28T23:05:01","modified_gmt":"2018-12-28T23:05:01","slug":"bash-yes-command-linux-hint","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/27\/bash-yes-command-linux-hint\/","title":{"rendered":"Bash yes Command \u2013 Linux Hint"},"content":{"rendered":"<p>Bash `yes` command is one of those commands of Linux that is related to the operation of another command. Using this command is useless when you execute the command independently. By default, `yes` command repeats the character \u2018y\u2019 if no string value is specified with this command. When `yes` command uses with pipe and another command then it will send the value \u2018y\u2019 or `yes` for any confirmation prompt. This command can help to save time by doing many confirmation tasks automatically.<\/p>\n<p>You can use `yes` command with an option or any string value, but both are optional for this command.<\/p>\n<p>yes [OPTION]<\/p>\n<p>yes [STRING]\u2026<\/p>\n<h2>Options<\/h2>\n<p>This command has not more options. Two options of this command are mentioned below.<\/p>\n<p>\u2013version<\/p>\n<p>It is used to display the installed version of this command.<\/p>\n<p>\u2013help<\/p>\n<p>It is used to get detail information of this command.<\/p>\n<h3>Example#1:<\/h3>\n<p>When you run the `yes` command without any option and string value then it will print \u2018y\u2019 for infinite times.<\/p>\n<p>Output:<\/p>\n<p>The following output will appear.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/1-32.png\" alt=\"\" width=\"735\" height=\"234\" \/><\/p>\n<h3>Example#2:<\/h3>\n<p>When you run the `yes` command with a specific string value then it will print the string value for infinite times.<\/p>\n<p>Output:<\/p>\n<p>The following output will appear.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/2-29.png\" alt=\"\" width=\"738\" height=\"184\" \/><\/p>\n<h3>Example#3:<\/h3>\n<p>`cp` command is used in bash to create any new file by copying an existing file. If the new filename exists then it will ask for overwrite permission if you run cp command with -i option. In this example, two text files hello.txt and sample.txt are used. If these two text files exist in the current location and `cp` command is run for copying sample.txt to hello.txt with -i option then it will ask for overwrite permission.<\/p>\n<p>$ cat hello.txt<br \/>\n$ cat sample.txt<br \/>\n$ cp -i sample.txt hello.txt<\/p>\n<p>You can use `yes` command to prevent from overwriting the existing file or forcefully overwrite the existing file. In the following commands, the first command is used to prevent the overwrite and the second command is used to overwrite the file without any permission.<\/p>\n<p>$ yes n | cp -i sample.txt hello.txt<br \/>\n$ yes | cp -i sample.txt hello.txt<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/3-27.png\" alt=\"\" width=\"975\" height=\"396\" \/><\/p>\n<h3>Example#4<\/h3>\n<p>You can use `yes` command to run any script multiple times in the command line. In this example, `yes` command is used to run while loop repeatedly ten times. Here, `yes` command will continuously send the numeric value from 1 to 10 to the loop and the loop will print the values in regular interval of one second.<\/p>\n<p>$ yes &#8220;$(seq 1 10)&#8221; | while read n; do echo $n; sleep 1; done<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/4-26.png\" alt=\"\" width=\"732\" height=\"430\" \/><\/p>\n<h3>Example#5:<\/h3>\n<p>You can use `yes` command to send any string value to a script while executing the script file. Create a bash file named \u2018yes_script.sh\u2019 and add the following script. If you run the script using `yes` command with empty string then it will print \u201cEmpty value is passed by yes command\u201d otherwise it will print the string value send by `yes` command by combining with other string.<\/p>\n<p>#!\/bin\/bash<\/p>\n<p>#Read the value passed from yes commandread string<\/p>\n<p>#check the string value is empty or notif [ &#8220;$string&#8221; == &#8220;&#8221; ]; then<\/p>\n<p>echo &#8220;Empty value is passed by yes command&#8221;<\/p>\n<p>elsenewstr=&#8221;The value passed by yes command is $string&#8221;<\/p>\n<p>echo $newstr<br \/>\nfi<\/p>\n<p>Run the `yes` command with an empty string and the bash script file, yes_script.sh.<\/p>\n<p>$ yes &#8220;&#8221; | bash yes_script.sh<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/5-28.png\" alt=\"\" width=\"731\" height=\"127\" \/><\/p>\n<p>Run the yes command with a string value, \u201ctesting\u201d and the bash script file, yes_script.sh.<\/p>\n<p>$ yes testing | bash yes_script.sh<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/6-26.png\" alt=\"\" width=\"731\" height=\"121\" \/><\/p>\n<h3>Example#6:<\/h3>\n<p>You can use `yes` command for the testing purpose also. You can run the following command to create a file with a huge amount of data for testing. After executing the command, a file named \u2018testfile\u2019 will be created that will contain 50 lines with the content, \u2018Add this line for testing\u2019.<\/p>\n<p>$ yes &#8216;Add this line for testing&#8217; | head -50 &gt; testfile<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/7-27.png\" alt=\"\" width=\"734\" height=\"97\" \/><\/p>\n<h4>Conclusion<\/h4>\n<p>The basic uses of `yes` command are shown in this tutorial by using different types of examples. It is a very useful command when you are confirmed about any task and don\u2019t want to waste time for unnecessary confirmation. You can use this command for some advanced level tasks, such as comparing processors ability or the loading capacity of any computer system etc.<\/p>\n<p><a href=\"https:\/\/linuxhint.com\/bash_yes_command\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bash `yes` command is one of those commands of Linux that is related to the operation of another command. Using this command is useless when you execute the command independently. By default, `yes` command repeats the character \u2018y\u2019 if no string value is specified with this command. When `yes` command uses with pipe and another &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/27\/bash-yes-command-linux-hint\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bash yes Command \u2013 Linux Hint&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6200","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=6200"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6200\/revisions"}],"predecessor-version":[{"id":6825,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6200\/revisions\/6825"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=6200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=6200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=6200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}