advertisement

2021年9月14日

What is /dev/null 2>&1 linux file descriptor 0 1 2 for stdin, stdout and stderr In the shell, what does " 2>&1 " mean?

 

         The input stream is referred to as "standard input"; the output
       stream is referred to as "standard output"; and the error stream
       is referred to as "standard error".  These terms are abbreviated
       to form the symbols used to refer to these files, namely stdin,
       stdout, and stderr.
         On program startup, the integer file descriptors associated with
       the streams stdin, stdout, and stderr are 0, 1, and 2,
       respectively.  The preprocessor symbols STDIN_FILENO,
       STDOUT_FILENO, and STDERR_FILENO are defined with these values in
       <unistd.h>.


There are also symbolic constants defined in unistd.h for the file descriptors belonging to the standard streams stdinstdout, and stderr; see Standard Streams.

STDIN_FILENO

This macro has value 0, which is the file descriptor for standard input.

STDOUT_FILENO

This macro has value 1, which is the file descriptor for standard output.

STDERR_FILENO

This macro has value 2, which is the file descriptor for standard error output.


File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.

Consider >& as redirect merger operator.


Ref:

https://www.gnu.org/software/libc/manual/html_node/Descriptors-and-Streams.html

https://man7.org/linux/man-pages/man3/stdout.3.html

https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean?noredirect=1&lq=1

Double pipe Double logical and Control operators

 

expression )

Returns the value of expression. This may be used to override the normal precedence of operators.

expression

True if expression is false.

expression1 && expression2

True if both expression1 and expression2 are true.

expression1 || expression2

True if either expression1 or expression2 is true.

The && and || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.


For example:

Code:
$ ls this_file_does_not_exist.txt || echo KO
ls: cannot access this_file_does_not_exist.txt: No such file or directory
KO

$ ls this_file_exist.txt && echo OK
this_file_exist.txt
OK


Ref:

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Command-Grouping

https://pongsona.wordpress.com/2011/12/03/what-does-double-pipe-mean/


What does @: (at symbol colon) mean in a Makefile?

 https://stackoverflow.com/questions/8610799/what-does-at-symbol-colon-mean-in-a-makefile

https://unix.stackexchange.com/questions/192241/file-function-in-makefile-takes-args-prefixed-by-symbol



2021年6月29日

台北市 北市 市政府 市民服務電話 聯絡 聯繫方式 客服 疫苗施打 臺北

 臺北市民當家熱線 (02)2720-8889


歡迎加入台北市政府Line好友
https://line.me/R/ti/p/@taipei?from=page


以及下載台北通APP
https://id.taipei/tpcd/about/taipeipass-app


以利掌握北市最新資訊,並便於使用實聯制與各項服務 👍


台北市民關心您😉

2021年4月20日

linux下 串列埠 工具 串口 序列埠 軟體 linux putty alternative for serial

 請參考此篇文章 Use Serial Port To Remote Control


使用cu command

cu -l /dev/device -s baud-rate-speed

# cu -l /dev/ttyS0 -s 57600

若出現

cu: open (/dev/ttyS0): Permission denied

cu: /dev/ttyS0: Line in use

請打下列指令確認權限

# ls -la /dev/ttyUSB0

# chmod 666 /dev/ttyUSB0


ref:https://superuser.com/questions/794309/linux-tells-me-a-serial-port-is-in-use-but-it-isnt/1155172

https://www.cyberciti.biz/hardware/5-linux-unix-commands-for-connecting-to-the-serial-console/

2021年4月6日

Debian Buster 10 root $PATH in bash does not include /sbin and /usr/sbin

 Debian 10 切換root超級使用者權限,超級使用者/管理者指令找不到,下echo $PATH發現環境變數與一般使用者一樣。

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

$ su
密碼:

# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games


根據Debian官方說明 Debian 10 su 指令是使用了util-linux套件,其PATH使用預設值且不會警告,若要切換至超級使用者與環境變數,須下達 su - 或 su -l 或 su --login ,三者亦同。

$ su -
密碼:
root@debian10:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


Reference:

https://wiki.debian.org/NewInBuster

https://unix.stackexchange.com/questions/460478/debian-su-and-su-path-differences

 

#ifconfig, #debian 10, #debian buster, #chpasswd, #fdisk, ,#useradd, #lsmod, #command not found, #指令找不到, #命令找不到