{"id":373,"date":"2021-07-24T23:04:20","date_gmt":"2021-07-24T17:34:20","guid":{"rendered":"https:\/\/blog.al-zakirah202.familyds.com\/?p=373"},"modified":"2021-07-24T23:04:20","modified_gmt":"2021-07-24T17:34:20","slug":"the-cshrc-file-in-a-tcsh-shell","status":"publish","type":"post","link":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/2021\/07\/24\/the-cshrc-file-in-a-tcsh-shell\/","title":{"rendered":"The &#8220;.cshrc&#8221; file in a tcsh shell"},"content":{"rendered":"<p>The &#8220;tcsh&#8221; shell is a unix shell based on and backward compatible with the C shell. \u00a0The terminal which&#8217;s an application for running unix shells like tcsh, bash, zsh..etc is one of the key features of a Mac system. \u00a0The shell lets you run unix command using the terminal and lets you automate things. <!--more-->It&#8217;s rightly said that engineers would love the terminal and the shell&#8217;s capabilities as it lets you create a script to run repetitive tasks. \u00a0There may types of shells and we are not going to dwell into that topic in this post. \u00a0But, I want to start with tcsh as it&#8217;s the first shell I learnt, specifically we&#8217;ll discuss about the &#8220;.cshrc&#8221; file which can used to source environment variables, define aliases, add few more info to your shell prompt..etc. \u00a0This file gets sourced when you open a tcsh shell\/terminal.<\/p>\n<h3>Location of the &#8220;.cshrc&#8221; file<\/h3>\n<ul>\n<li>We can use one of the text editors like <em>&#8220;Vi&#8221;<\/em> or <em>&#8220;Vim&#8221;<\/em> to create this file. \u00a0This file needs to be located in the user&#8217;s home directory on the unix file system. \u00a0It&#8217;s important to note that this is a hidden file and the file name starts with a dot (&#8220;.&#8221;) indicating that it&#8217;s hidden.<\/li>\n<li>In other-words, if you go and run a <em>&#8220;ls -ltr&#8221;<\/em> command in your home directory then you won&#8217;t see this file\n<p><div id=\"attachment_375\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-375\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM-1024x483.png\" alt=\"\" width=\"800\" height=\"377\" class=\"size-large wp-image-375\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM-1024x483.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM-300x142.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM-768x362.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM-1536x725.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.20.26-PM.png 1810w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-375\" class=\"wp-caption-text\">Output of ls -ltr run inside a home directory<\/p><\/div><\/li>\n<li>And you need to run\u00a0<em>&#8220;ls -ltra&#8221; (&#8216;a&#8217; is for all files both hidden and normal)\u00a0<\/em>to see the .cshrc file\n<div id=\"attachment_376\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-376\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-1024x211.png\" alt=\"\" width=\"800\" height=\"165\" class=\"size-large wp-image-376\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-1024x211.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-300x62.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-768x158.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-1536x317.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.23.26-PM-2048x423.png 2048w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-376\" class=\"wp-caption-text\">Output of &#8216;ls -ltra&#8217; showing the .cshrc file<\/p><\/div>\n<p>&nbsp;<\/li>\n<\/ul>\n<h3>Contents of the &#8220;.cshrc&#8221; file<\/h3>\n<h4>Aliases:<\/h4>\n<ul>\n<li>You could use the alias command to alias a text or a string to a specific set of characters. \u00a0As an example, I have put the below 3 aliases in my .cshrc file which will let the shell execute the full command when I type in just the alias.\n<div id=\"attachment_378\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-378\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.28.08-PM-1024x162.png\" alt=\"\" width=\"800\" height=\"127\" class=\"size-large wp-image-378\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.28.08-PM-1024x162.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.28.08-PM-300x47.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.28.08-PM-768x121.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.28.08-PM.png 1344w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-378\" class=\"wp-caption-text\">Alias examples<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><div id=\"attachment_379\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-379\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM-1024x457.png\" alt=\"\" width=\"800\" height=\"357\" class=\"size-large wp-image-379\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM-1024x457.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM-300x134.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM-768x343.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM-1536x686.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.29.20-PM.png 2016w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-379\" class=\"wp-caption-text\">Shell executing &#8220;ls -ltr&#8221; using the alias &#8220;l&#8221;<\/p><\/div><\/li>\n<\/ul>\n<h4>Adding more info to the command prompt<\/h4>\n<ul>\n<li>You can add more information like username, date or time to the command prompt as well. \u00a0This makes the command prompt look cool with added information. \u00a0For example the below 2 commands sets the left prompt and right side prompt information\n<div id=\"attachment_380\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-380\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM-1024x64.png\" alt=\"\" width=\"800\" height=\"50\" class=\"size-large wp-image-380\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM-1024x64.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM-300x19.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM-768x48.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM-1536x97.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.35.25-PM.png 1622w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-380\" class=\"wp-caption-text\">Commands for the left &amp; right prompts in the .cshrc file<\/p><\/div>\n<p>&nbsp;<\/li>\n<li>The first command causes the full path of the directory we are in to be displayed in the blue colour on the left and the second command causes the date in the format DD-Month-YYYY and time in the format &#8220;HH:MM:SS&#8221; to be displayed in white colour on the right.\n<div id=\"attachment_381\" style=\"width: 991px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-381\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-1024x537.png\" alt=\"\" width=\"981\" height=\"515\" class=\" wp-image-381\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-1024x537.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-300x157.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-768x403.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-1536x806.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.39.03-PM-2048x1074.png 2048w\" sizes=\"auto, (max-width: 981px) 100vw, 981px\" \/><p id=\"caption-attachment-381\" class=\"wp-caption-text\">Left &amp; Right prompts in a terminal<\/p><\/div>\n<p>&nbsp;<\/li>\n<\/ul>\n<h4>Local &amp; Environment variables<\/h4>\n<ul>\n<li>You can also set local and environmental variables using the &#8220;.cshrc&#8221; file. \u00a0For example, the below two commands sets the variable &#8220;rmstar&#8221; and the environmental variable &#8220;PATH&#8221;\n<p><div id=\"attachment_387\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-387\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-1024x44.png\" alt=\"\" width=\"800\" height=\"34\" class=\"size-large wp-image-387\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-1024x44.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-300x13.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-768x33.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-1536x67.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-11.02.03-PM-2048x89.png 2048w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-387\" class=\"wp-caption-text\">Examples for manipulating variables using &#8220;.cshrc&#8221; file<\/p><\/div><\/li>\n<li>The rmstar variable causes a warning message to be displayed when the user executes &#8220;rm *&#8221; command (which means remove every file) asking whether do you really want to delete all the files. \u00a0It&#8217;s very useful to avoid inadvertent running of &#8220;rm *&#8221; command which could wipe off the entire suite of files.\n<p><div id=\"attachment_383\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-383\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-1024x104.png\" alt=\"\" width=\"800\" height=\"81\" class=\"size-large wp-image-383\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-1024x104.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-300x31.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-768x78.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-1536x156.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.46.13-PM-2048x208.png 2048w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-383\" class=\"wp-caption-text\">Warning message of &#8220;rm *&#8221; command<\/p><\/div><\/li>\n<li>The PATH environment variable is very useful feature of the shell. \u00a0Whenever the user executes a command from the command prompt, the shell looks into the &#8220;PATH&#8221; environment variable to find out the whereabouts of the command executable. \u00a0If the user enters a command (say &#8216;junk&#8217;) whose executable isn&#8217;t present in any of the paths defined in the &#8220;PATH&#8221; environment variable then it issues an error saying &#8220;Command not found.&#8221; \u00a0This feature is very useful to add your own suite of scripts you have developed and just point the PATH variable to include the directory path of your scripts (in my case, it&#8217;s in the path &#8220;\/Users\/amjad\/scripts&#8221;). \u00a0Now for executing any command or script located in that folder, I need not type the entire path of the script on the prompt. \u00a0Rather, I just need to type the name of the command and shell would use the PATH variable to locate the directory. \u00a0Yes, it&#8217;s very useful \ud83d\ude00\n<div id=\"attachment_384\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-384\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-1024x47.png\" alt=\"\" width=\"800\" height=\"37\" class=\"size-large wp-image-384\" srcset=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-1024x47.png 1024w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-300x14.png 300w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-768x35.png 768w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-1536x71.png 1536w, https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/uploads\/2021\/07\/Screenshot-2021-07-24-at-10.52.56-PM-2048x94.png 2048w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p id=\"caption-attachment-384\" class=\"wp-caption-text\">Example of a command whose path is not known<\/p><\/div>\n<p>&nbsp;<\/li>\n<\/ul>\n<p>Yes, you could do lot more using the &#8220;.cshrc&#8221; file and the above are some examples of its features. \u00a0Feel free to give \ud83d\udc4d to the post!<\/p>\n<div id=\"emojics-root\"><\/div><div class=\"remoji_bar\"><div class=\"remoji_container\" data-remoji-id=\"373\" data-remoji-type=\"post\" data-remoji-name=\"thumbsup\"><img decoding=\"async\" src=\"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-content\/plugins\/remoji\/data\/emoji\/1f44d.svg\"><span class=\"remoji_count\">3<\/span><\/div><div class=\"remoji_add_container\" data-remoji-id=\"373\" data-remoji-type=\"post\"><div class=\"remoji_add_icon\"><\/div><\/div><div class=\"remoji_error_bar\" data-remoji-id=\"373\" data-remoji-type=\"post\" style=\"display: none;\">Error happened.<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>The &#8220;tcsh&#8221; shell is a unix shell based on and backward compatible with the C shell. \u00a0The terminal which&#8217;s an application for running unix shells like tcsh, bash, zsh..etc is one of the key features of a Mac system. \u00a0The shell lets you run unix command using the terminal and lets you automate things. 3Error [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":374,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,16],"tags":[18],"class_list":["post-373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tcsh","category-terminal","tag-cshrc"],"_links":{"self":[{"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":3,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"predecessor-version":[{"id":388,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/posts\/373\/revisions\/388"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/media\/374"}],"wp:attachment":[{"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.al-zakirah202.familyds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}