TransWikia.com

Create reusable functions bash

Unix & Linux Asked by HDev007 on November 11, 2021

I have the following the curl command :-

curl --cert certificate_file.pem:password -i -X POST -H 'Content-Type:application/json' -d '{somedata}' 

below part of curl would be common

curl –cert certificate_file.pem:password

How can I make it reusable and call?

One Answer

You can even use an alias for that, since the first part remains constant.

alias mycurl='curl --cert certificate_file.pem:password'

If you insist on a function, this could work:

function mycurl()
{
    curl --cert certificate_file.pem:password "$@"
}

Both can now be invoked this way:

mycurl -i -X POST -H 'Content-Type:application/json' -d '{somedata}'

Answered by Artem S. Tashkinov on November 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP