LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   bash scripting question (http://www.linuxquestions.org/questions/slackware-14/bash-scripting-question-4175457690/)

Bazzaah 04-10-2013 01:08 PM

bash scripting question
 
I realise that this might be in the wrong forum so please move mods if you feel the need, but it is a Slackware specific question.

I've been playing with a script to automate kernel compilation (to some extent).

The commands I use come from AlienBob's guide and I know they work.

My question is this - would the first three lines of code take the user input and insert that input into the variable $kernel in line 4? I think it does but would like to check.

Code:

#!/bin/bash
1. echo -n "Which kernel?"
2. read kernel
3. echo "kernel $KERNEL"
4. tar -C /usr/src -Jxf linux-$kernel.tar.xz
...rest of script...

Thanks in advance

ruario 04-10-2013 01:23 PM

No because the variables have case sensitive naming, $KERNEL is not the same as $kernel.

What is with the line numbers?

P.S. Also you don't need the J switch for tar. It will detect that it is XZ compressed automatically. You could rewite that line as:
Code:

tar xf linux-$kernel.tar.xz -C /usr/src
EDIT: Also why not just trying running the script and you would have seen if it worked or not?

Bazzaah 04-10-2013 01:50 PM

Quote:

Originally Posted by ruario (Post 4929147)
No because the variables have case sensitive naming, $KERNEL is not the same as $kernel.

What is with the line numbers?

P.S. Also you don't need the J switch for tar. It will detect that it is XZ compressed automatically. You could rewite that line as:
Code:

tar xf linux-$kernel.tar.xz -C /usr/src
EDIT: Also why not just trying running the script and you would have seen if it worked or not?

Thanks ruario.

I just added the line numbers to make my question clear - they don't appear in the script.

re your question, fair comment. I know little about bash scripting and wanted to check.

Didier Spaier 04-10-2013 01:58 PM

Small tip: when you request the user to enter data, use "read -e" instead of "read". This allows some line editing.


All times are GMT -5. The time now is 07:48 AM.