Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create UNIX "special character" file

Suppose I want to create, in the spirit of /dev/zero, a file /dev/seven that produces the character '7' whenever it is read from. How should I go about doing something like this? Would I need to modify the kernel?

like image 951
koschei Avatar asked May 24 '11 05:05

koschei


People also ask

How do you add special characters in Unix?

About Unix standard multi-key support If a character is unavailable on the keyboard, you can insert the character by pressing the special Compose key followed by a sequence of two other keys. See the table below for the keys used to insert various characters. Note that in Amaya you can change the order of the two keys.

How do you create a filename with special characters in Linux?

Explanation. Double your \ , like this: \\ , so that your shell does not interpret the backslashes from your filename as escape characters. Escape " and ' , like this: \" , \' , so that your shell interprets the double quotes as part of the filename.

What is $@ in Unix?

$@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

What is $() called in Bash?

It turns out, $() is called a command substitution. The command in between $() or backticks (“) is run and the output replaces $() . It can also be described as executing a command inside of another command.


2 Answers

Yes, you'd need to create a driver for that special character device.

For linux, I'd suggest you read Linux Device Drivers by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman. (Chapter 3 talks about char drivers, but do read at least the first two chapters also.)

like image 158
Mat Avatar answered Sep 22 '22 14:09

Mat


A device driver is not necessary, a fifo special file plus a user program generating the stream of 7 is perfectly able to provide this behavior.

You'll need about a five line shell script, all told.

like image 35
Ben Voigt Avatar answered Sep 25 '22 14:09

Ben Voigt