{"id":491,"date":"2022-12-15T16:51:22","date_gmt":"2022-12-15T16:51:22","guid":{"rendered":"https:\/\/bootstrap-it.com\/blog\/?p=491"},"modified":"2022-12-15T18:08:57","modified_gmt":"2022-12-15T18:08:57","slug":"pair-programming-with-the-chatgpt-ai-how-well-does-gpt-3-5-understand-bash","status":"publish","type":"post","link":"https:\/\/bootstrap-it.com\/blog\/?p=491","title":{"rendered":"Pair Programming with the ChatGPT AI &#8211; how well does GPT-3.5 understand Bash?"},"content":{"rendered":"<div id=\"s-share-buttons\" class=\"horizontal-w-c-circular s-share-w-c\"><a href=\"http:\/\/www.facebook.com\/sharer.php?u=https:\/\/bootstrap-it.com\/blog\/?p=491\" target=\"_blank\" title=\"Share to Facebook\" class=\"s3-facebook hint--top\"><\/a><a href=\"http:\/\/twitter.com\/intent\/tweet?text=Pair Programming with the ChatGPT AI &#8211; how well does GPT-3.5 understand Bash?&url=https:\/\/bootstrap-it.com\/blog\/?p=491\" target=\"_blank\"  title=\"Share to Twitter\" class=\"s3-twitter hint--top\"><\/a><a href=\"http:\/\/reddit.com\/submit?url=https:\/\/bootstrap-it.com\/blog\/?p=491&title=Pair Programming with the ChatGPT AI &#8211; how well does GPT-3.5 understand Bash?\" target=\"_blank\" title=\"Share to Reddit\" class=\"s3-reddit hint--top\"><\/a><a href=\"http:\/\/www.linkedin.com\/shareArticle?mini=true&url=https:\/\/bootstrap-it.com\/blog\/?p=491\" target=\"_blank\" title=\"Share to LinkedIn\" class=\"s3-linkedin hint--top\"><\/a><a href=\"mailto:?Subject=Pair%20Programming%20with%20the%20ChatGPT%20AI%20&#8211;%20how%20well%20does%20GPT-3.5%20understand%20Bash?&Body=Here%20is%20the%20link%20to%20the%20article:%20https:\/\/bootstrap-it.com\/blog\/?p=491\" title=\"Email this article\" class=\"s3-email hint--top\"><\/a><\/div>\n<p>You can watch a <a href=\"https:\/\/youtube.com\/watch?v=GxJKuINwPSw%3Ffeature%3Doembed\">video version of this article here<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash?\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/GxJKuINwPSw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>We&#8217;ve been hearing about artificial intelligence and natural language processing &#8211; and in particular about the latest version of OpenAI&#8217;s GPT &#8211; for weeks. The recent release of GPT 3.5, and specifically the very new ChatGPT tool is definitely a huge leap forward.<\/p>\n\n\n\n<p>I&#8217;m sure you&#8217;ve read about people asking the AI to draw up real estate contracts and wills and even generate programming code. This article approaches the tool from a slightly different perspective.<\/p>\n\n\n\n<p>I decided to see how ChatGPT handles Linux Bash scripting. But (spoiler alert!) as I worked through the tool&#8217;s suggestions &#8211; both good code and bad code &#8211; I began to realize that there was an even more powerful benefit staring me in the face: an opportunity to pair-program with a eminently helpful partner.<\/p>\n\n\n\n<p>The AI ultimately failed to solve my problem, but the <em>way<\/em> it failed was absolutely fascinating. And watching the AI searching for new answers was absolutely crazy.<\/p>\n\n\n\n<p>So let&#8217;s see how it all happened. Here. more or less, is the initial prompt I provided to the AI:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Write me a Bash script that prompts for the URL of a YouTube video and then uses the yt-dlp program to download from that URL. The script should then change the file name to &#8220;myvideo.mp4&#8221;<\/p>\n<\/blockquote>\n\n\n\n<p>After a few seconds, the ChatGPT told me that a script was coming. Here&#8217;s how that code looked:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Prompt user for YouTube video URL\nread -p \"Enter YouTube video URL: \" url\n\n# Download video from YouTube using yt-dlp\nyt-dlp $url\n\n# Get the name of the downloaded video file\nyt-dlp $url\n\n# Change the downloaded video filename to \"myvideo.mkv\"\nmv video-filename.mp4 myvideo.mp4<\/code><\/pre>\n\n\n\n<p>The AI obviously knows what Bash scripts are and how to present code. It even did a great job commenting each line of code. The AI knows how to properly prompt the user for input and then how to import the input string into a variable called <code>url<\/code>.<\/p>\n\n\n\n<p>It also knows about the yt-dlp program and how it works; appropriately feeding it the URL that was provided. Then it at least attempted to rename the downloaded video file to myvideo.mp4. But everything kind of broke down when it assumed that the download filename would be video-filename.mp4. Whoops.<\/p>\n\n\n\n<p>At any rate, the AI helpfully showed me how to create the script from its code and then run it.<\/p>\n\n\n\n<p>My first follow-up prompt pointed out the obvious mistake and, after a few seconds, ChatGPT admitted it was wrong and offered an improvement.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>You&#8217;re right, the script I provided would not work as expected because it assumes that the downloaded video will be saved to a file with the name <code>video-filename.mp4<\/code>. However, this is not guaranteed to be the case. To fix this&#8230;<\/p>\n<\/blockquote>\n\n\n\n<p>It&#8217;s just mind-blowing how the AI is completely engaged in the process here. It remembers its first code, listens to and understands my complaint, and thinks through a solution. Here&#8217;s that second attempt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Prompt user for YouTube video URL\nread -p \"Enter YouTube video URL: \" url\n\n# Download video from YouTube using yt-dlp\nyt-dlp $url\n\n# Get the name of the downloaded video file\nfilename=$(basename $url)\n\n# Change the downloaded video filename to \"myvideo.mkv\"\nmv $filename.mp4 myvideo.mp4<\/code><\/pre>\n\n\n\n<p>Ok, so I can see how the solution kind of looked right &#8211; <code>basename<\/code> is a Linux tool that can strip out file system directories and leave nothing but the actual filename. The problem is that the variable <code>url<\/code> doesn&#8217;t contain a local filename, but an internet address. This one definitely isn&#8217;t going to work.<\/p>\n\n\n\n<p>So I tried again, explaining how that wasn&#8217;t the right tool for the job. And ChatGPT gives it another try.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Prompt user for YouTube video URL\nread -p \"Enter YouTube video URL: \" url\n\n# Extract the filename from the URL\nfilename=$(basename $url)\n\n# Download the video using the yt-dlp tool and specify the filename\nyt-dlp -o $filename $url\n\n# Change the downloaded video filename to \"myvideo.mkv\"\nmv $filename.mp4 myvideo.mp4<\/code><\/pre>\n\n\n\n<p>This time, it shows that it had familiarized itself with the yt-dlp documentation, suggesting that we use the <code>-o<\/code> argument to give the downloading video a name, against which <code>basename<\/code> should now work. With each iteration, the AI gives me this updated code for my cutting and pasting pleasure.<\/p>\n\n\n\n<p>Of course, that wasn&#8217;t going to work either. With the next attempt, I get the feeling that the AI is a bit desperate.<\/p>\n\n\n\n<p>I&#8217;m going to skip past the next attempt or two, as we ran into a side problem: Videos coming from YouTube aren&#8217;t always MP4s, they&#8217;re sometimes MKVs or even WEBMs. That uncertainty could mess with the filenames we&#8217;re working with, so I asked ChatGPT to work that into the code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Prompt user for YouTube video URL\nread -p \"Enter YouTube video URL: \" url\n\n# Extract the filename from the URL\nfilename=$(basename $url)\n\n# Download the video using the yt-dlp tool and specify the filename\nyt-dlp -F mp4 -O $filename $url\n\n# Change the downloaded video filename to \"myvideo.mkv\"\nmv $filename.mp4 myvideo.mp4<\/code><\/pre>\n\n\n\n<p>When I reported how that, too, wouldn&#8217;t work, the AI started to get confused. First it told me that the <code>-F<\/code> option was expecting a valid video format, but that &#8220;mp4&#8221; wasn&#8217;t valid. Then it gives me valid options, including &#8220;mp4&#8221;.<\/p>\n\n\n\n<p>When nothing the AI suggested worked, it gave up, advising me to make sure that yt-dlp was actually installed on my machine and showing me how to do that. I figured that was a good time to give up. It was a surprisingly good effort and, even if it didn&#8217;t solve the problem, it did show me some useful syntax and got me thinking.<\/p>\n\n\n\n<p>In case you&#8217;re interested, by the way, here&#8217;s how an actual working script would look.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Prompt user for YouTube video URL\nread -p \"Enter YouTube video URL: \" url\n\n# Download video from YouTube using yt-dlp\nyt-dlp $url\n\n# Get the name of the downloaded video file\noriginal_filename=$(ls | awk '\/mp4\/ || \/webm\/ || \/mkv\/')\n\n# Change the downloaded video filename to \"myvideo.mkv\"\nmv \"$original_filename\" \/home\/ubuntu\/vids\/myvideo.mp4<\/code><\/pre>\n\n\n\n<p>The first two lines of code are just the way ChatGPT suggested. But I then isolate the filename by listing all the files in the current directory and using <code>awk<\/code> to filter for only filenames containing either mp4, webm, or mkv. (This assumes that there will never be more than one video file in the directory at a time.)<\/p>\n\n\n\n<p>The filename will then be written to the <code>original_filename<\/code> variable. I&#8217;ll then use that variable as part of a <code>move<\/code> command to rename the file <code>myvideo.mp4<\/code> As far as I can tell, that&#8217;ll work no matter what format was actually sent.<\/p>\n\n\n\n<p><em>Besides my <a href=\"https:\/\/www.youtube.com\/@davidbclinton\">my YouTube channel<\/a> (to which you can subscribe), <a href=\"https:\/\/bootstrap-it.com\">my website<\/a> links to all kinds of technology goodness available as articles, books, and courses.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can watch a video version of this article here: We&#8217;ve been hearing about artificial intelligence and natural language processing &#8211; and in particular about the latest version of OpenAI&#8217;s GPT &#8211; for weeks. The recent release of GPT 3.5,&hellip; <a href=\"https:\/\/bootstrap-it.com\/blog\/?p=491\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":496,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bootstrap-it.com\/blog\/?p=491\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT\" \/>\n<meta property=\"og:description\" content=\"You can watch a video version of this article here: We&#8217;ve been hearing about artificial intelligence and natural language processing &#8211; and in particular about the latest version of OpenAI&#8217;s GPT &#8211; for weeks. The recent release of GPT 3.5,&hellip; Continue Reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bootstrap-it.com\/blog\/?p=491\" \/>\n<meta property=\"og:site_name\" content=\"Bootstrap IT\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-15T16:51:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-15T18:08:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bootstrap-it.com\/blog\/wp-content\/uploads\/chat_home_page.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1862\" \/>\n\t<meta property=\"og:image:height\" content=\"1053\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"dbclin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@davidbclinton\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dbclin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bootstrap-it.com\/blog\/?p=491\",\"url\":\"https:\/\/bootstrap-it.com\/blog\/?p=491\",\"name\":\"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT\",\"isPartOf\":{\"@id\":\"https:\/\/bootstrap-it.com\/blog\/#website\"},\"datePublished\":\"2022-12-15T16:51:22+00:00\",\"dateModified\":\"2022-12-15T18:08:57+00:00\",\"author\":{\"@id\":\"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/ae0fb1d5b3b01558b92b6426d77766ec\"},\"breadcrumb\":{\"@id\":\"https:\/\/bootstrap-it.com\/blog\/?p=491#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bootstrap-it.com\/blog\/?p=491\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bootstrap-it.com\/blog\/?p=491#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bootstrap-it.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pair Programming with the ChatGPT AI &#8211; how well does GPT-3.5 understand Bash?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bootstrap-it.com\/blog\/#website\",\"url\":\"https:\/\/bootstrap-it.com\/blog\/\",\"name\":\"Bootstrap IT\",\"description\":\"Learn technology using technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bootstrap-it.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/ae0fb1d5b3b01558b92b6426d77766ec\",\"name\":\"dbclin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a93785d437350478a7f1dfcbec58d26bc28e0124e405179acbe1b4325c09f90a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a93785d437350478a7f1dfcbec58d26bc28e0124e405179acbe1b4325c09f90a?s=96&d=mm&r=g\",\"caption\":\"dbclin\"},\"sameAs\":[\"http:\/\/bootstrap-it.com\/\",\"dbclinton\",\"https:\/\/twitter.com\/davidbclinton\"],\"url\":\"https:\/\/bootstrap-it.com\/blog\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bootstrap-it.com\/blog\/?p=491","og_locale":"en_US","og_type":"article","og_title":"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT","og_description":"You can watch a video version of this article here: We&#8217;ve been hearing about artificial intelligence and natural language processing &#8211; and in particular about the latest version of OpenAI&#8217;s GPT &#8211; for weeks. The recent release of GPT 3.5,&hellip; Continue Reading &rarr;","og_url":"https:\/\/bootstrap-it.com\/blog\/?p=491","og_site_name":"Bootstrap IT","article_published_time":"2022-12-15T16:51:22+00:00","article_modified_time":"2022-12-15T18:08:57+00:00","og_image":[{"width":1862,"height":1053,"url":"https:\/\/bootstrap-it.com\/blog\/wp-content\/uploads\/chat_home_page.png","type":"image\/png"}],"author":"dbclin","twitter_card":"summary_large_image","twitter_creator":"@davidbclinton","twitter_misc":{"Written by":"dbclin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/bootstrap-it.com\/blog\/?p=491","url":"https:\/\/bootstrap-it.com\/blog\/?p=491","name":"Pair Programming with the ChatGPT AI - how well does GPT-3.5 understand Bash? - Bootstrap IT","isPartOf":{"@id":"https:\/\/bootstrap-it.com\/blog\/#website"},"datePublished":"2022-12-15T16:51:22+00:00","dateModified":"2022-12-15T18:08:57+00:00","author":{"@id":"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/ae0fb1d5b3b01558b92b6426d77766ec"},"breadcrumb":{"@id":"https:\/\/bootstrap-it.com\/blog\/?p=491#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bootstrap-it.com\/blog\/?p=491"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/bootstrap-it.com\/blog\/?p=491#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bootstrap-it.com\/blog"},{"@type":"ListItem","position":2,"name":"Pair Programming with the ChatGPT AI &#8211; how well does GPT-3.5 understand Bash?"}]},{"@type":"WebSite","@id":"https:\/\/bootstrap-it.com\/blog\/#website","url":"https:\/\/bootstrap-it.com\/blog\/","name":"Bootstrap IT","description":"Learn technology using technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bootstrap-it.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/ae0fb1d5b3b01558b92b6426d77766ec","name":"dbclin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bootstrap-it.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a93785d437350478a7f1dfcbec58d26bc28e0124e405179acbe1b4325c09f90a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a93785d437350478a7f1dfcbec58d26bc28e0124e405179acbe1b4325c09f90a?s=96&d=mm&r=g","caption":"dbclin"},"sameAs":["http:\/\/bootstrap-it.com\/","dbclinton","https:\/\/twitter.com\/davidbclinton"],"url":"https:\/\/bootstrap-it.com\/blog\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=491"}],"version-history":[{"count":6,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":500,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions\/500"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/496"}],"wp:attachment":[{"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bootstrap-it.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}