Multiplication on command line terminal

后端 未结 8 1915
有刺的猬
有刺的猬 2020-12-04 08:00

I\'m using a serial terminal to provide input into our lab experiment. I found that using

$ echo \"5X5\"

just returns a string of \"

8条回答
  •  隐瞒了意图╮
    2020-12-04 08:30

    I have a simple script I use for this:

    me@mycomputer:~$ cat /usr/local/bin/c

    #!/bin/sh
    
    echo "$*" | sed 's/x/\*/g' | bc -l
    

    It changes x to * since * is a special character in the shell. Use it as follows:

    • c 5x5
    • c 5-4.2 + 1
    • c '(5 + 5) * 30' (you still have to use quotes if the expression contains any parentheses).

提交回复
热议问题