开发者

Some doubts with Shell Scripting.

开发者 https://www.devze.com 2023-03-23 13:59 出处:网络
I have a couple of requirements to be satisfied using shell scripts. Since I am trio in this area, i would certainly need your help.

I have a couple of requirements to be satisfied using shell scripts. Since I am trio in this area, i would certainly need your help.

1) I have a script which invokes a env-function which will ask for a user input to proceed with the execution. I want my script to supply the answer to this. How can i implement this.

Doing a bit of googling pointed me to an "expect" command, which is unfortunately not installed in my system. Is there any other way to achieve this task?

2) I have another requirement like, the script should find the total number of CPUs in my pc and should append the "-j(2*no.开发者_StackOverflow社区 of CPU)" to my make command.

Could somebody please shed some light into how this can be done.

Thanks,

Sen


Since the first part has been answered, for the 2nd part you can try something like

#!/bin/sh 

cpu=`cat /proc/cpuinfo | grep -e '^processor' | wc -l`
jobs=$(echo "$cpu * 2" | bc)

make -j$jobs


I have another requirement like, the script should find the total number of CPUs in my pc

You can read the output of /proc/cpuinfo

or even better:

You can narrow down output with the following command, to display number of processors in the system:

grep processor /proc/cpuinfo


you can simply redirect an input to that program. An example with checkinstall:

checkinstall < /path/to/file/with/answers
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号