DEV Community

Shubham Kumar Gupta
Shubham Kumar Gupta

Posted on

Bash Variables

Bash Variables

In the bash shell, variables are used to store values. Variables can be declared and assigned values using the following syntax:

variable_name=value
Enter fullscreen mode Exit fullscreen mode

For example:

name="Shubham Kumar Gupta"
Enter fullscreen mode Exit fullscreen mode

To reference the value stored in a variable, prefix the variable name with a '$' symbol.

echo "My name is $name"
Enter fullscreen mode Exit fullscreen mode
  • In bash, variables can store string, integer or floating-point values.
  • Variable names are case-sensitive.
  • Varibale names can only contain letters, numbers, and underscores and they must start with a letter or an underscore.

How to change $PATH variable

  • The $PATH variable in bash defines the search path for executables.
  • We can change it by modifying the contents of the $PATH environment variable.

Few ways to modify the $PATH variable in bash:

  • Temporarily modify $PATH for the current shell session:
PATH="$PATH:/new/directory"
Enter fullscreen mode Exit fullscreen mode
  • Permanently modify $PATH for the current user:
echo 'export PATH="$PATH:/new/directory"' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Permanently modify $PATH for the system-wide shell:
echo 'export PATH="$PATH:/new/directory"' >> /etc/environment
Enter fullscreen mode Exit fullscreen mode
  • In each of the above examples, replace /new/directory with the path to the directory you want to add to the $PATH variable.
  • After modifying the $PATH variable, you may need to log out and log back in or restart your terminal session for the changes to take effect.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay