![]() In our first command, we download a picture and print its binary contents to stdout using the âoutput â option.| curl -X POST -data -H 'Content-Type: text/plain' Weâll do all these tasks only by reading and writing to stdin and stdout, without having to save the contents in a file on the disk: $ curl -output - \ Once the image is resized, weâll convert it to base64 and POST the result to an endpoint. In our next example, weâll write a command that basically downloads a picture using curl and then creates a favicon out of the image using ImageMagick. Well, we can do a lot of useful tasks with it. So, one might wonder why we print the binary output to our standard output. Like stdin, when â-â is used in the context of stdout, itâs an alias for /dev/stdout. Using â-â to Specify a Standard OutputĮ�P��7�&�3Dq�"!GKvL�[f>׫��GY6as���bmLf-~r+�����ju��WTrĪs we can see, we explicitly told the curl command to output the contents of the binary file because, by default, curl will not print binary contents to stdout. Then, we can pipe whatever is printed to the stdout to tar and specify the contents of the stdout as stdin: $ curl -L -output - | tar zxf. We can use curl to print the text or binary output of the downloaded file to the stdout. The -f option writes the extracted contents to a file or directoryĪnother practical use-case of using tar with â-â is when we want to download a remote file and extract it once it is downloaded. ![]() The -z option filters the contents through gzip.The -x option extracts the file, or the contents of stdout in this case.Then we pipe the command to tar, which reads the contents of the htop-2.2.0.tar.gz from stdout.We print the contents of the htop-2.2.0.tar.gz archive to stdout using the redirect operator The contents of the tarball printed to stdout will act as input to the tar command, which will untar the contents and write them to the disk as shown in the following snippet: $ that reason, weâre able to input text to the cat command using our terminal. ![]() The /proc/self/fd/0, in turn, is a symbolic link to the standard input of our current shell process, which is our terminal. So, it begs the question, what is /dev/stdin? Well, /dev/stdin is a symbolic link to /proc/self/fd/0. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |