# Running huggingface-cli from script

**URL:** <https://discuss.huggingface.co/t/running-huggingface-cli-from-script/17338>\
**Category:** Intermediate\
**Created:** [April 29, 2022, 3:39pm UTC](https://discuss.huggingface.co/t/running-huggingface-cli-from-script/17338 "2022-04-29T15:39:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pere](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pere/32/40613_2.png) [@pere](https://discuss.huggingface.co/u/pere)\
**Post date:** [April 29, 2022, 3:39pm UTC](https://discuss.huggingface.co/t/running-huggingface-cli-from-script/17338/1 "2022-04-29T15:39:32Z")

</div>

I am using startup scripts on my TPU, and need to authenticate for access to my datasets with “huggingface-cli cli” as part of the script.

Typically something like this should work:  
`printf "myaccesstoken\n" | huggingface-cli login`

However, this does not work. Any idea how to authenticate as part of a batch script?

---

<div class="post-metadata">

**Author:** ![julien-c](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/julien-c/32/41937_2.png) [@julien-c](https://discuss.huggingface.co/u/julien-c)\
**Post date:** [May 1, 2022, 3:32pm UTC](https://discuss.huggingface.co/t/running-huggingface-cli-from-script/17338/2 "2022-05-01T15:32:24Z")

</div>

You can probably just call `HfFolder.save_token()` which will save your token to `~/.huggingface/token`

Let us know if it worked (also cc @lysandre)

---

<div class="post-metadata">

**Author:** ![pere](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pere/32/40613_2.png) [@pere](https://discuss.huggingface.co/u/pere)\
**Post date:** [May 2, 2022, 12:37pm UTC](https://discuss.huggingface.co/t/running-huggingface-cli-from-script/17338/3 "2022-05-02T12:37:19Z")

</div>

Great. Thanks. This seems to work perfectly in my bash script:

python -c “from huggingface\_hub.hf\_api import HfFolder; HfFolder.save\_token(‘my\_token’)”
