Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

null-character

What is the difference between (char)0 and ‘\0’? in C

January 4, 2024 by Tarik

They’re both a 0, but (char) 0 is a char, while ‘\0’ is (unintuitively) an int. This type difference should not usually affect your program if the value is 0. I prefer ‘\0’, since that is the constant intended for that.

Categories c Tags c++, null-character Leave a comment

Assign string containing null-character (\0) to a variable in Bash

August 22, 2023 by Tarik

In Bash, you can’t store the NULL-character in a variable. You may, however, store a plain hex dump of the data (and later reverse this operation again) by using the xxd command. VAR1=`echo -ne “n\0m\0k” | xxd -p | tr -d ‘\n’` echo -ne “$VAR1” | xxd -r -p | od -c # -> 0000000 … Read more

Categories bash Tags bash, null-character Leave a comment

Reading null delimited strings through a Bash loop

March 5, 2023 by Tarik

The preferred way to do this is using process substitution while IFS= read -r -d $’\0′ file; do # Arbitrary operations on “$file” here done < <(find /some/path -type f -print0) If you were hell-bent on parsing a bash variable in a similar manner, you can do so as long as the list is not … Read more

Categories bash Tags bash, delimiter, null-character Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa