{"id":345,"date":"2023-11-12T17:17:49","date_gmt":"2023-11-12T17:17:49","guid":{"rendered":"https:\/\/sparkonelabs.com\/home\/?p=345"},"modified":"2023-11-12T17:33:56","modified_gmt":"2023-11-12T17:33:56","slug":"arch-linux-shell-scripts-bash-return-local-ip","status":"publish","type":"post","link":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/","title":{"rendered":"Arch Linux Shell Scripts: Bash return local IP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This post is a note in case I have to rewrite the .bashrc on system crash or some such potential catastrophe. In order to facilitate shell based configuration, it is helpful to have .bashrc display the local and public IP address (IPv4). To that end a simple shell script can be added to .bashrc creating the desired outcome.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Local IP Address<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following ip command will display the local IP address only:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ip address | grep \"inet 192.\" | grep -o -E \"&#91;0-9]{3}\\.&#91;0-9]{3}\\.&#91;0-9]{1}\\.&#91;0-9]{3}\\\/\" | grep -o -E \"&#91;0-9]{3}\\.&#91;0-9]{3}\\.&#91;0-9]{1}\\.&#91;0-9]{3}\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There is probably a better way to do it and if you have any suggestions feel free to comment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Public IP Address<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following command will display the public ip address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl ipinfo.io\/ip<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">References:<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"\"><a href=\"https:\/\/www.reddit.com\/r\/kde\/comments\/kfqqui\/konsole_default_profile\/\">https:\/\/www.reddit.com\/r\/kde\/comments\/kfqqui\/konsole_default_profile\/<\/a> &#8211; Set default profile in Konsole<\/li>\n\n\n\n<li class=\"\"><a href=\"https:\/\/www.google.com\/search?q=bash+echo+with+no+newline&amp;oq=bash+echo+with+no+newline&amp;gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQLhhA0gEINjYzMWowajGoAgCwAgA&amp;sourceid=chrome&amp;ie=UTF-8\">https:\/\/www.google.com\/search?q=bash+echo+with+no+newline&amp;oq=bash+echo+with+no+newline&amp;gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQLhhA0gEINjYzMWowajGoAgCwAgA&amp;sourceid=chrome&amp;ie=UTF-8<\/a> &#8211; echo with no \\n<\/li>\n\n\n\n<li class=\"\"><a href=\"https:\/\/www.google.com\/search?q=grep+show+only+first+match+in+line&amp;oq=grep+show+only+first+match+in+line&amp;gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQLhhA0gEINDE5OWowajSoAgCwAgA&amp;sourceid=chrome&amp;ie=UTF-8\">https:\/\/www.google.com\/search?q=grep+show+only+first+match+in+line&amp;oq=grep+show+only+first+match+in+line&amp;gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQLhhA0gEINDE5OWowajSoAgCwAgA&amp;sourceid=chrome&amp;ie=UTF-8<\/a> &#8211; grep only first match<\/li>\n\n\n\n<li class=\"\"><a href=\"https:\/\/www.unix.com\/shell-programming-and-scripting\/234273-regex-match-only-first-occurence-grep.html\">https:\/\/www.unix.com\/shell-programming-and-scripting\/234273-regex-match-only-first-occurence-grep.html<\/a> &#8211; Use regex to filter out just the local IP address<\/li>\n\n\n\n<li class=\"\"><a href=\"https:\/\/stackoverflow.com\/questions\/14594151\/methods-to-detect-public-ip-address-in-bash\">https:\/\/stackoverflow.com\/questions\/14594151\/methods-to-detect-public-ip-address-in-bash<\/a> &#8211; display public id address in bash<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This post is a note in case I have to rewrite the .bashrc on system crash or some such potential catastrophe. In order to facilitate shell based configuration, it is helpful to have .bashrc display the local and public IP address (IPv4). To that end a simple shell script can be added to .bashrc creating<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site<\/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:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site\" \/>\n<meta property=\"og:description\" content=\"This post is a note in case I have to rewrite the .bashrc on system crash or some such potential catastrophe. In order to facilitate shell based configuration, it is helpful to have .bashrc display the local and public IP address (IPv4). To that end a simple shell script can be added to .bashrc creating\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/\" \/>\n<meta property=\"og:site_name\" content=\"SparkOne() Labs Official Site\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/profile.php?id=61551444286908\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-12T17:17:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-12T17:33:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/sparkonelabs.com\/home\/wp-content\/uploads\/2024\/01\/logo_sparkone_12.png?fit=1152%2C896&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1152\" \/>\n\t<meta property=\"og:image:height\" content=\"896\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sparkonelabs\" \/>\n<meta name=\"twitter:site\" content=\"@sparkonelabs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#\\\/schema\\\/person\\\/ee3bd21f007818ac04abf178e749642c\"},\"headline\":\"Arch Linux Shell Scripts: Bash return local IP\",\"datePublished\":\"2023-11-12T17:17:49+00:00\",\"dateModified\":\"2023-11-12T17:33:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/\"},\"wordCount\":232,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/\",\"url\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/\",\"name\":\"Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#website\"},\"datePublished\":\"2023-11-12T17:17:49+00:00\",\"dateModified\":\"2023-11-12T17:33:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/2023\\\/11\\\/12\\\/arch-linux-shell-scripts-bash-return-local-ip\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arch Linux Shell Scripts: Bash return local IP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/\",\"name\":\"SparkOne() Labs Official Site\",\"description\":\"SparkOne Labs is a Science, Art and Technology blog. Email: sparkonelabs@sparkonelabs.com\",\"publisher\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#organization\"},\"alternateName\":\"SparkOne Labs\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#organization\",\"name\":\"SparkOne() Labs\",\"alternateName\":\"SparkOne Labs\",\"url\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/logo_sparkone_12.png\",\"contentUrl\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/logo_sparkone_12.png\",\"width\":1152,\"height\":896,\"caption\":\"SparkOne() Labs\"},\"image\":{\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/profile.php?id=61551444286908\",\"https:\\\/\\\/x.com\\\/sparkonelabs\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/#\\\/schema\\\/person\\\/ee3bd21f007818ac04abf178e749642c\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/sparkonelabs.com\\\/home\"],\"url\":\"https:\\\/\\\/sparkonelabs.com\\\/home\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site","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:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/","og_locale":"en_US","og_type":"article","og_title":"Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site","og_description":"This post is a note in case I have to rewrite the .bashrc on system crash or some such potential catastrophe. In order to facilitate shell based configuration, it is helpful to have .bashrc display the local and public IP address (IPv4). To that end a simple shell script can be added to .bashrc creating","og_url":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/","og_site_name":"SparkOne() Labs Official Site","article_publisher":"https:\/\/www.facebook.com\/profile.php?id=61551444286908","article_published_time":"2023-11-12T17:17:49+00:00","article_modified_time":"2023-11-12T17:33:56+00:00","og_image":[{"width":1152,"height":896,"url":"https:\/\/i0.wp.com\/sparkonelabs.com\/home\/wp-content\/uploads\/2024\/01\/logo_sparkone_12.png?fit=1152%2C896&ssl=1","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@sparkonelabs","twitter_site":"@sparkonelabs","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/#article","isPartOf":{"@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/"},"author":{"name":"admin","@id":"https:\/\/sparkonelabs.com\/home\/#\/schema\/person\/ee3bd21f007818ac04abf178e749642c"},"headline":"Arch Linux Shell Scripts: Bash return local IP","datePublished":"2023-11-12T17:17:49+00:00","dateModified":"2023-11-12T17:33:56+00:00","mainEntityOfPage":{"@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/"},"wordCount":232,"commentCount":0,"publisher":{"@id":"https:\/\/sparkonelabs.com\/home\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/","url":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/","name":"Arch Linux Shell Scripts: Bash return local IP - SparkOne() Labs Official Site","isPartOf":{"@id":"https:\/\/sparkonelabs.com\/home\/#website"},"datePublished":"2023-11-12T17:17:49+00:00","dateModified":"2023-11-12T17:33:56+00:00","breadcrumb":{"@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sparkonelabs.com\/home\/2023\/11\/12\/arch-linux-shell-scripts-bash-return-local-ip\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sparkonelabs.com\/home\/"},{"@type":"ListItem","position":2,"name":"Arch Linux Shell Scripts: Bash return local IP"}]},{"@type":"WebSite","@id":"https:\/\/sparkonelabs.com\/home\/#website","url":"https:\/\/sparkonelabs.com\/home\/","name":"SparkOne() Labs Official Site","description":"SparkOne Labs is a Science, Art and Technology blog. Email: sparkonelabs@sparkonelabs.com","publisher":{"@id":"https:\/\/sparkonelabs.com\/home\/#organization"},"alternateName":"SparkOne Labs","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sparkonelabs.com\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/sparkonelabs.com\/home\/#organization","name":"SparkOne() Labs","alternateName":"SparkOne Labs","url":"https:\/\/sparkonelabs.com\/home\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparkonelabs.com\/home\/#\/schema\/logo\/image\/","url":"https:\/\/sparkonelabs.com\/home\/wp-content\/uploads\/2024\/01\/logo_sparkone_12.png","contentUrl":"https:\/\/sparkonelabs.com\/home\/wp-content\/uploads\/2024\/01\/logo_sparkone_12.png","width":1152,"height":896,"caption":"SparkOne() Labs"},"image":{"@id":"https:\/\/sparkonelabs.com\/home\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/profile.php?id=61551444286908","https:\/\/x.com\/sparkonelabs"]},{"@type":"Person","@id":"https:\/\/sparkonelabs.com\/home\/#\/schema\/person\/ee3bd21f007818ac04abf178e749642c","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bc8a8c84ca952e624e7407ec63589bc91e7996574dee7a01c13a96c536c341e9?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/sparkonelabs.com\/home"],"url":"https:\/\/sparkonelabs.com\/home\/author\/admin\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/comments?post=345"}],"version-history":[{"count":5,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/posts\/345\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/media?parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/categories?post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sparkonelabs.com\/home\/wp-json\/wp\/v2\/tags?post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}