# Node Attributes within bash script

**URL:** <https://discourse.chef.io/t/node-attributes-within-bash-script/10938>\
**Category:** Chef Infra (archive)\
**Created:** [May 22, 2017, 1:21pm UTC](https://discourse.chef.io/t/node-attributes-within-bash-script/10938 "2017-05-22T13:21:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Hawkins](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@Simon\_Hawkins](https://discourse.chef.io/u/Simon_Hawkins)\
**Post date:** [May 22, 2017, 1:21pm UTC](https://discourse.chef.io/t/node-attributes-within-bash-script/10938/1 "2017-05-22T13:21:31Z")

</div>

Hi there,

Is there any way of using a chef node attribute within a bash script?

In my repo i have an [config.sh](http://config.sh) script to deploy my app and within this script it would be nice to reference like:

#!/bin/sh  
MYDIR=node[:file\_location][:mydir]

And then in the script "mv /tmp/file.txt /test/$MYDIR

Is it possible?

Cheers,  
Simon.

---

<div class="post-metadata">

**Author:** ![donwlewis](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/donwlewis/32/1846_2.png) [@donwlewis](https://discourse.chef.io/u/donwlewis)\
**Post date:** [May 22, 2017, 1:26pm UTC](https://discourse.chef.io/t/node-attributes-within-bash-script/10938/2 "2017-05-22T13:26:37Z")

</div>

The way I would do this is to leverage a template within your cookbook that would generate the BASH script prior to executing it. This is how I have leveraged attributes within a BASH script. It is either that, or use a ruby block to search and replace text.

---

<div class="post-metadata">

**Author:** ![Simon\_Hawkins](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@Simon\_Hawkins](https://discourse.chef.io/u/Simon_Hawkins)\
**Post date:** [May 23, 2017, 8:17am UTC](https://discourse.chef.io/t/node-attributes-within-bash-script/10938/3 "2017-05-23T08:17:48Z")

</div>

Hiya,

Many thanks - this works a treat!

Cheers,  
Simon.
