简体   繁体   中英

Using bash script to use return status of one C program as arg to another

I have two compiled.c files and I am trying to take the exit status of the first and use it as an arg to the next one.

#!/bash/bin

./decipher $1
key = $?
./cipher $key $1 $2

This is what I am typing on the command line $./decryption_tool.bs ceaser1.txt output.txt .ceaser1.txt is an encrypted message and decipher will return a key and cipher should take that key and unencrypt it. Both files work outside of the script as well, but when i use the script I get this error.

./decryption_tool.bs: line 4: key: command not found
./decryption_tool.bs: line 5:  5937 Segmentation fault      (core dumped) ./cipher $key $1 $2

Thanks for any help.

Few things wrong:

  1. You cannot have spaces when you set variables in shell script - it should be key=$? instead of key = $?
  2. Invalid shebang: not #!/bash/bin , but #!/bin/bash or even better #!/usr/bin/env bash
  3. It would be good to surround variables in double quotes: ./cipher "$key" "$1" "$2"
  4. Why file extension is .bs ? For shell script it's .sh and Bash doesn't have its own separate version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM