LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to use Vi editor to run a script from LFS website (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-use-vi-editor-to-run-a-script-from-lfs-website-4175442578/)

DavidLee1A 12-22-2012 12:46 PM

How to use Vi editor to run a script from LFS website
 
checking my host system requirements using the LFS script located at: http://www.linuxfromscratch.org/lfs/.../hostreqs.html
It starts with cat > version-check.sh << "EOF"
and ends with EOF

What is the best way to modify this to write it in the Vi editor?
Do I have to change the cat command and do something like
~$ Vi version-check.sh ? Then, how do I have to modify the script? I already typed the entire script verbatim and called the file versioncheck.

markush 12-22-2012 12:56 PM

It is a so called here document, the cat command writes the text between << "EOF" and EOF into the file named version-check.sh

If you want to do it with an editor you would have to type the complete script manually or copy and paste it from the website.

To write it manually do
Code:

vi version-check.sh
then you are in the editor. You would have to leave the first line (with the cat command) and everything from EOF to the end. But afterwards you would have to execute (after closing the editor)
Code:

bash version-check.sh
Markus

BTW: most easy is to copy the complete script into a terminal and press the <ENTER> key.
Then happens this
Code:

markus@samsung:~$ cat > version-check.sh << "EOF"
> #!/bin/bash
> # Simple script to list version numbers of critical development tools
>
> export LC_ALL=C
> bash --version | head -n1 | cut -d" " -f2-4
> echo "/bin/sh -> `readlink -f /bin/sh`"
> echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
> bison --version | head -n1
> if [ -e /usr/bin/yacc ];
>  then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
>  else echo "yacc not found"; fi
>
> bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
> echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
> diff --version | head -n1
> find --version | head -n1
> gawk --version | head -n1
> if [ -e /usr/bin/awk ];
>  then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
>  else echo "awk not found"; fi
>
> gcc --version | head -n1
> ldd --version | head -n1 | cut -d" " -f2-  # glibc version
> grep --version | head -n1
> gzip --version | head -n1
> cat /proc/version
> m4 --version | head -n1
> make --version | head -n1
> patch --version | head -n1
> echo Perl `perl -V:version`
> sed --version | head -n1
> tar --version | head -n1
> echo "Texinfo: `makeinfo --version | head -n1`"
> xz --version | head -n1
>
> echo 'main(){}' > dummy.c && gcc -o dummy dummy.c
> if [ -x dummy ]
>  then echo "gcc compilation OK";
>  else echo "gcc compilation failed"; fi
> rm -f dummy.c dummy
> EOF
markus@samsung:~$
markus@samsung:~$ bash version-check.sh
bash, version 4.2.37(2)-release
/bin/sh -> /bin/bash
Binutils: (Linux/GNU Binutils) 2.22.52.0.2.20120424
bison (GNU Bison) 2.5.1
/usr/bin/yacc -> /usr/bin/yacc
bzip2,  Version 1.0.6, 6-Sept-2010.
Coreutils:  8.19
diff (GNU diffutils) 3.2
find (GNU findutils) 4.4.2
GNU Awk 3.1.8
/usr/bin/awk -> /bin/gawk-3.1.8
gcc (GCC) 4.7.1
(GNU libc) 2.15
grep (GNU grep) 2.14
gzip 1.5
Linux version 3.5.4 (root@srv-zuhause) (gcc version 4.7.1 (GCC) ) #1 SMP Sun Sep 23 12:15:31 CEST 2012
m4 (GNU M4) 1.4.16
GNU Make 3.82
GNU patch 2.7
Perl version='5.16.1';
GNU sed version 4.2.1
tar (GNU tar) 1.26
Texinfo: makeinfo (GNU texinfo) 4.13
xz (XZ Utils) 5.0.4
gcc compilation OK
markus@samsung:~$


DavidLee1A 12-22-2012 01:21 PM

Markush, Thank You for the quick reply! I would cut and paste but for many reasons:
1) I am on Chapter 7 of: http://rute.2038bug.com/node10.html.gz and he says everyone should be familiar with Vi
2) The work is being done on another computer that has a minimal Debian install and commands like | less and lynx don't seem work, I haven't even connected to a website from there yet ... so, no pasting yet

It will be a few hours and I'll post how this worked. Thank you again.

markush 12-22-2012 01:23 PM

If you want to learn vi, I would recommend to do it on a computer where vim is installed (which is a vi clone). vim comes with an interactive tutorial, simply type
Code:

vimtutor
in a terminal.

Markus

DavidLee1A 12-24-2012 05:47 PM

well markush, I did a round of vimtutor and wrote this:
Code:

#!/bin/bash

# Simple script to list version numbers of critical development tools

export LC_ALL=C

bash --version | head -n1 | cut -d" " -f2-4

echo "/bin/sh -> `readlink -f /bin/bash`"

echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-

bison --version | head -n1

if [ -e /usr/bin/yacc ];

  then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";

  else echo "yacc not found"; fi

bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-

echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2

diff --version | head -n1

find --version | head -n1

gawk --version | head -n1

if [ -e /usr/bin/awk ];

  then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";

  else echo "awk not found"; fi

gcc --version | head -n1

ldd --version | head -n1 | cut -d" " -f2- # glibc version

grep --version | head -n1

gzip --version | head -n1

cat /proc/version

m4 --version | head -n1

make --version | head -n1

patch --version | head -n1

echo Perl `perl -V:version`

sed --version | head -n1

tar --version | head -n1

echo "Texinfo: `makeinfo --version | head -n1`"

xz --version | head -n1

echo 'main(){}' > dummy.c && gcc -o dummy dummy.c

if [ -x dummy ]

  then echo "gcc compilation OK";

  else echo "gcc compilation failed"; fi

rm -f dummy.c dummy

done

but I don't think I should have written done at the end b/c I get a syntax error unexpected token message at the end of this:
Code:

learner@host:~$ bash version-check.sh

bash, version 4.1.5(1)-release

/bin/sh -> /bin/bash

Binutils: (GNU Binutils for Debian) 2.20.1-system.20100303

bison (GNU Bison) 2.4.1

/usr/bin/yacc -> /usr/bin/bison.yacc

bzip2,  Version 1.0.5, 10-Dec-2007.

Coreutils:  8.5

diff (GNU diffutils) 3.0

find (GNU findutils) 4.4.2

GNU Awk 3.1.7

/usr/bin/awk -> /usr/bin/gawk

gcc (Debian 4.4.5-8) 4.4.5

(Debian EGLIBC 2.11.3-4) 2.11.3

GNU grep 2.6.3

gzip 1.3.12

Linux version 2.6.32-5-amd64 (Debian 2.6.32-46) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Sun Sep 23 10:07:46 UTC 2012

m4 (GNU M4) 1.4.14

GNU Make 3.81

patch 2.6

Perl version='5.10.1';

GNU sed version 4.2.1

tar (GNU tar) 1.23

Texinfo: makeinfo (GNU texinfo) 4.13

xz (XZ Utils) 5.0.0

gcc compilation OK

learner@host:~$ vim version-check.sh

learner@host:~$ bash version-check.sh

bash, version 4.1.5(1)-release

/bin/sh -> /bin/bash

Binutils: (GNU Binutils for Debian) 2.20.1-system.20100303

bison (GNU Bison) 2.4.1

/usr/bin/yacc -> /usr/bin/bison.yacc

bzip2,  Version 1.0.5, 10-Dec-2007.

Coreutils:  8.5

diff (GNU diffutils) 3.0

find (GNU findutils) 4.4.2

GNU Awk 3.1.7

/usr/bin/awk -> /usr/bin/gawk

gcc (Debian 4.4.5-8) 4.4.5

(Debian EGLIBC 2.11.3-4) 2.11.3

GNU grep 2.6.3

gzip 1.3.12

Linux version 2.6.32-5-amd64 (Debian 2.6.32-46) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Sun Sep 23 10:07:46 UTC 2012

m4 (GNU M4) 1.4.14

GNU Make 3.81

patch 2.6

Perl version='5.10.1';

GNU sed version 4.2.1

tar (GNU tar) 1.23

Texinfo: makeinfo (GNU texinfo) 4.13

xz (XZ Utils) 5.0.0

gcc compilation OK

version-check.sh: line 37: syntax error near unexpected token `done'

version-check.sh: line 37: `done'

But I still get the information I needed so: Thank you

druuna 12-25-2012 02:34 AM

Just type everything in between cat > version-check.sh << "EOF" and EOF (both not included) and do not add anything else.

The LFS book uses a here-document (as already mentioned by markush in posr #2). Here is a link explaining this construct: Here Documents (ABSG)

markush 12-25-2012 03:31 AM

The syntax error is the word 'done' which doesn't belong into the file.

Markus


All times are GMT -5. The time now is 12:15 AM.