Create reusable functions bash

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?

Unix & Linux Asked by HDev007 on November 11, 2021

1 Answers

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 "[email protected]"

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!

Related Questions

How to batch convert bitmaps to SVGs?

5  Asked on December 10, 2020 by village


xRDP sound redirection ubuntu 20.04

0  Asked on December 9, 2020 by hlderlin


bash script not running at startup

3  Asked on December 9, 2020 by hexodus


find’s prune’s -path is not taking wildcards

2  Asked on December 8, 2020 by pompy


Taking an integer and creating a date format

1  Asked on December 7, 2020 by alar-yldz


GPU Offloading using wayland and x11

1  Asked on December 6, 2020 by hjahre


File Creating with read permission for root user alone

0  Asked on December 6, 2020 by mpsimham


How to configure a GRE tunnel for ubuntu?

1  Asked on December 6, 2020 by natf2d


Ask a Question

Get help from others!

© 2021 All rights reserved.