Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

proper terminal alternatives

30 views
Skip to first unread message

Cal Dershowitz

unread,
Sep 7, 2013, 6:56:30 PM9/7/13
to
Hello NG,

I found myself at the terminal last week unable to chase down line 119
because I develop on gedit, which doesn't have a find line number
capability.

In desperation, I wrote a little perl utility to get close:

$ cat mcat.pl
#!/usr/bin/perl
use strict;
use warnings;
##usage file linenumber
open my $fh,'<', $ARGV[0] or die "can't open file: $!";
my @lines = <$fh>;
print "@lines\n"
my $number = $ARGV[1] or die "$!";
print "$lines($number)\n";
$

Talking to a friend about it, he said I should be able to get such data
off the terminal by using core commands, without being too specific.

What would I use to see the line before and after line number 37 of a file?

Thanks in advance.
--
Cal

Stachu 'Dozzie' K.

unread,
Sep 7, 2013, 7:04:44 PM9/7/13
to
On 2013-09-07, Cal Dershowitz <c...@example.invalid> wrote:
> Hello NG,
>
> I found myself at the terminal last week unable to chase down line 119
> because I develop on gedit, which doesn't have a find line number
> capability.

If you use a raw text editor instead of some IDE, why not use powerful
editor like Vim or Emacs?

> In desperation, I wrote a little perl utility to get close:
>
> $ cat mcat.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
> ##usage file linenumber
> open my $fh,'<', $ARGV[0] or die "can't open file: $!";
> my @lines = <$fh>;
> print "@lines\n"
> my $number = $ARGV[1] or die "$!";
> print "$lines($number)\n";

You should get "Global symbol ... requires explicit package name" error.
ITYM "$lines[$number]".

> Talking to a friend about it, he said I should be able to get such data
> off the terminal by using core commands, without being too specific.
>
> What would I use to see the line before and after line number 37 of a file?

You could use awk (NR variable), or you could use `sed -n' ("p" command
accepts line numbers). Or in Perl, you could use $. variable
(`perldoc perlvar'). Also, you may want to pay attention to `-n' option
to perl.

--
Secunia non olet.
Stanislaw Klekot

Lew Pitcher

unread,
Sep 7, 2013, 7:08:44 PM9/7/13
to
On Saturday 07 September 2013 18:56, in comp.unix.shell, c...@example.invalid
wrote:
head -38 the_file | tail -3



--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

Barry Margolin

unread,
Sep 7, 2013, 9:08:32 PM9/7/13
to
In article <r9CdnW7oj56CMrbP...@supernews.com>,
cat -n filename | grep -C 1 $'^ *37\t' | cut -f2-

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Ben Bacarisse

unread,
Sep 7, 2013, 9:55:10 PM9/7/13
to
Cal Dershowitz <c...@example.invalid> writes:

> I found myself at the terminal last week unable to chase down line 119
> because I develop on gedit, which doesn't have a find line number
> capability.
>
> In desperation, I wrote a little perl utility to get close:
>
> $ cat mcat.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
> ##usage file linenumber
> open my $fh,'<', $ARGV[0] or die "can't open file: $!";
> my @lines = <$fh>;
> print "@lines\n"
> my $number = $ARGV[1] or die "$!";
> print "$lines($number)\n";
> $

You could just do something like:

perl -ne 'print if 119-1..119+1'

By putting that in a shell function or alias you can avoid repeating the
line number.

<snip>
--
Ben.

Steve Youngs

unread,
Sep 7, 2013, 10:44:54 PM9/7/13
to
Cal Dershowitz <c...@example.invalid> writes:

> What would I use to see the line before and after line number 37 of
> a file?

sed -n 36,38p file

--
|---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
| Te audire no possum. |
| Musa sapientum fixa est in aure. |
|--------------------------------<st...@steveyoungs.com>---|

Cydrome Leader

unread,
Sep 9, 2013, 1:06:08 PM9/9/13
to
vi


Cal Dershowitz

unread,
Sep 10, 2013, 3:04:08 AM9/10/13
to
Thanks all for responses. I try to be a generous OP, in that I give the
satisfaction of seeing the respondents' code in action, but that's a
little south of where I want to be right now.

My deal with vi is that I went through a different toolchain. I'm an MS
kid in that I was programming on Windows in 1983, so I became accustomed
to that toolchain at least until it became malware.

Can you elaborate?
--
Cal

Geoff Clare

unread,
Sep 10, 2013, 8:43:55 AM9/10/13
to
Cal Dershowitz wrote:

> I found myself at the terminal last week unable to chase down line 119
> because I develop on gedit, which doesn't have a find line number
> capability.

Yes it does (at least, 3.4.2 the version I have does). Type Ctrl-I,
enter line number in pop-up box, press Return.

There is also an option in the preferences to make it display line
numbers.

--
Geoff Clare <net...@gclare.org.uk>

Aragorn

unread,
Sep 10, 2013, 3:02:35 PM9/10/13
to
On Tuesday 10 September 2013 09:04, Cal Dershowitz conveyed the
following to comp.unix.shell...
I believe Cydrome Leader was being both sarcastic and terse in his
reply, because vi displays line numbers, so when loading the file into
vi, you would naturally be able to "see the line before and after line
#37", as per your wording.

I presume that you want an ad hoc one-line command which does the job,
and then I think the replies you got from Lew Pitcher and Steve Youngs
would be the simplest and, indeed, most ad hoc.

--
= Aragorn =
GNU/Linux user #223157 - http://www.linuxcounter.net

Cal Dershowitz

unread,
Sep 18, 2013, 7:54:01 PM9/18/13
to
$ ls -al
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 .
drwxr-xr-x 5 fred automation 4096 Sep 18 14:05 ..
-rw-r--r-- 1 fred automation 358 Sep 18 15:11 eng_captions
-rw-r--r-- 1 fred automation 307 Sep 17 19:49 eng_captions~
-rw-r--r-- 1 fred automation 97 Sep 17 23:21 f
-rw-r--r-- 1 fred automation 74 Sep 17 22:16 f~
$ cd ..
$ pwd
/home/fred/Documents/root/pages/terminal

$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11 terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05 terminal2.pl
$ ./terminal2.pl my_ftp
files are images1/s1.png
Net::FTP>>> Net::FTP(2.77)
Net::FTP>>> Exporter(5.64_03)
Net::FTP>>> Net::Cmd(2.29)
Net::FTP>>> IO::Socket::INET(1.31)
Net::FTP>>> IO::Socket(1.32)
Net::FTP>>> IO::Handle(1.31)
Net::FTP=GLOB(0x896171c)<<< 220 FTP Server ready.
Net::FTP=GLOB(0x896171c)>>> USER u61210220
Net::FTP=GLOB(0x896171c)<<< 331 Password required for u61210220
Net::FTP=GLOB(0x896171c)>>> PASS ....
Net::FTP=GLOB(0x896171c)<<< 230 User u61210220 logged in
Net::FTP=GLOB(0x896171c)>>> TYPE I
Net::FTP=GLOB(0x896171c)<<< 200 Type set to I
Net::FTP=GLOB(0x896171c)>>> CWD /pages
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,208,51).
Net::FTP=GLOB(0x896171c)>>> NLST
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
file list
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
matching is 1 2 3
new word is terminal_4
html file is terminal_4.html
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
Net::FTP=GLOB(0x896171c)>>> CWD images/
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> MKD terminal_4/
Net::FTP=GLOB(0x896171c)<<< 550 terminal_4/: File exists
Cannot create directory terminal_4/: File exists
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
files are captions/eng_captions captions/eng_captions~ captions/f
captions/f~
text is This shows three different ways to get lines 35 to 38 in a file
called bc1.pl. This script is new and is supposed to take the hyperlink
I post right here, and expand it properly to html:
http://www.youtube.com/watch?v=6qBwCmhIHq0 . Everywhere we hear the
sounds of revolution; we just don't see any.

The square root of 3 is Washington's birthday: 1732.

text is <p class="hft-paras">This shows three different ways to get
lines 35 to 38 in a file called bc1.pl. This script is new and is
supposed to take the hyperlink I post right here, and expand it properly
to html: <a href="http://www.youtube.com/watch?v=6qBwCmhIHq0"
class="hft-urls">http://www.youtube.com/watch?v=6qBwCmhIHq0</a> .
Everywhere we hear the sounds of revolution; we just don&#39;t see any. </p>

<p class="hft-paras">The square root of 3 is Washington&#39;s birthday:
1732.</p>

Net::FTP=GLOB(0x896171c)>>> CWD /images/terminal_4/
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
name is images1/s1.png
remote is s1.png
Net::FTP=GLOB(0x896171c)>>> ALLO 93069
Net::FTP=GLOB(0x896171c)<<< 200 ALLO command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,217,190).
Net::FTP=GLOB(0x896171c)>>> STOR s1.png
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
s1.png
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
Net::FTP=GLOB(0x896171c)>>> PWD
Net::FTP=GLOB(0x896171c)<<< 257 "/images/terminal_4" is the current
directory
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,251,94).
Net::FTP=GLOB(0x896171c)>>> NLST
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
file list
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11 terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05 terminal2.pl
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
Net::FTP=GLOB(0x896171c)>>> CWD /pages
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> ALLO 1379
Net::FTP=GLOB(0x896171c)<<< 200 ALLO command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,208,14).
Net::FTP=GLOB(0x896171c)>>> STOR terminal_4.html
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
terminal_4.html
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
$ cat terminal2.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use File::Basename;
use Cwd;
use HTML::FromText;
use Text::Template;
use File::Slurp;

## usage needs 1 arg from argv my_ftp
#identity and config
my $ident = 'ident.txt';
my ( $config, $domain );
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}
$domain = $config->{ $ARGV[0] };
die("unknown domain: $ARGV[0]") unless $domain;
# get local files
my $path = "images1/";
my @files = <$path*>;
print " files are @files\n";
#dial up the server
my $ftp = Net::FTP->new( $domain->{domain}, Debug => 1, Passive => 1 )
or die "Can't connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} )
or die "Couldn't login\n";
$ftp->binary();
# go to /pages
$ftp->cwd("/pages") or die "Cannot change working directory ",
$ftp->message;
# show working directory
my $dir = cwd;
my $word = basename($dir);
# get files from remote root that end in php:
my @remote_files = $ftp->ls();
# make unique .html choice
my @matching = map /${word}_(\d+)\.html/, @remote_files;
print "matching is @matching\n";
push( @matching, 0 );
@matching = sort { $a <=> $b } @matching;
my $winner = pop @matching;
my $newnum1 = $winner + 1;
my $word2 = "${word}_$newnum1";
print " new word is $word2\n";
my $html_file = "${word2}.html";
print "html file is $html_file\n";
#make directory in images to correspond
$ftp->cdup();
$ftp->cwd("images/")
or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("${word2}/")
or warn "Cannot create directory ", $ftp->message;
$ftp->cdup();
# create unicode html file
open( my $fh, ">:utf8", $html_file )
or die("Can't open $html_file for writing: $!");
my $input = "template_stuff/hc_input2.txt";
# write in the header
open( my $gh, "<:utf8", $input ) or die("Can't open: $!");
my $template2 = Text::Template->new(SOURCE => $input)
or die "Couldn't construct template: $Text::Template::ERROR";
my %vars = (
title => $word,
headline => 'Helpful Unix Commands',
place => 'Oakland',
css_file => 'rad1.css',
);
my $now_string = localtime;
$vars{date} = $now_string;
my $result = $template2->fill_in(HASH => \%vars);
if (defined $result) { print $fh $result }
else { die "Couldn't fill in template: $Text::Template::ERROR" };
#create template outside loop
my $template = <<'TEMPLATE';
<img src="http://www.merrillpjensen.com/images/%s"/>
%s
TEMPLATE
#get captions
my $dir2 = "captions/";
my @files2 = <$dir2*>;
@files2 = sort @files2;
print "files are @files2\n";
local $/ = undef;
my $string = read_file($files2[0]);
print "text is $string\n";
my $kludge = text2html(
$string,
urls => 1,
email => 1,
paras => 1,
);

print "text is $kludge\n";

$ftp->cwd("/images/${word2}/") or die "cwd failed $@\n";
# main control
for my $name (@files) {

# captions
my $caption = $kludge;
print "name is $name\n";
my $remote_file = basename($name);
print "remote is $remote_file\n";
$ftp->put( $name, $remote_file ) or die "put failed $!\n";
printf $fh $template, "${word2}/" . $remote_file, $caption;

}

# write in the footer
my $footer = "template_stuff/footer_center.txt";
open( my $hh, "<:utf8", $footer )
or die("Can't open: $!");
while (<$hh>) {
print $fh $_;
}
close $fh;
$ftp->pwd();
$ftp->ls();
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cwd("/pages") or die "Cannot change working directory ",
$ftp->message;
$ftp->put($html_file) or die "put failed $@\n";



$

http://merrillpjensen.com/pages/terminal_4.html

I finally kludged this into place. I'm looking to do this in more
generality and breaking this up into pieces that bash move around
instead of my arthritic fingers.

I'm moving away from this particular template to another, and I'd like
to do it in some generality, the type one achieves with bash. There
seems to be some things you can best do with perl and others with unix.
Almost nothing can't be done on a 'puter with the combination used
effectively.

I will be relatively-new to studying servers to the local crowd in
c.u.s.. What I lack in experience I make up for, in some measure, by
reading. I'm in the alpaca book at the beginning of the chapter on
references to subroutines.

So I'm gonna chop that all up and take the first slice where I defined
the variable $kludge. Ben will like that I was being descriptive.

Q1) How would bash determine the highest number .pl in this:

$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11 terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05 terminal2.pl

Thanks for your comment,
--
Cal


Cal Dershowitz

unread,
Sep 18, 2013, 8:06:32 PM9/18/13
to
Thank you, geoff, would you believe that I hadn't figured out that there
was functionality for me up top with gedit?

USER ERROR.

It's funny when you just get busted cold blaming your computer for
something that was your own blindness.

It forced me to use perl. Has anyone ever thought of the notion before
that there could me more than one way to do things?
--
Cal

Cal Dershowitz

unread,
Sep 18, 2013, 9:17:07 PM9/18/13
to
Thx, Lou, I find that the easiest to use, if you didn't look at "coming
down to the terminal" like being forced into uncomfortable circumstances
here in the laundry room to tap at a keyboard, oh wait...(Don't let me
complain, it only makes things worse.)

Anyways, it did not, despite expectations, kill me; it only made my
templates stronger. They take their name from their directory. The
first line in this will definitely be a part of the bash template I'm
looking to write.

$ cp -rf terminal leprechaun
$ ls
about cleaning1.php~ music2.pl php1.sh
about1.css contact nikon_bash1.sh phpini.sh
about1.css~ cp_1.pl nikon_bash2.sh portfolio
about2.css fredify2.sh nikon_bash3.sh quaternions
about2.css~ git1.txt nikon_bash3.sh~ reg1.pl
bash3.sh git1.txt~ nikon_bash4.sh reg2.pl
boycott_2.html hammer.jpg nikon_bash5.sh reg2.pl.bak
boycott_2.html~ index.php nikon_bash5.sh~ server1.sh
boycott_2.php jesse nikon_bash6.sh server1.sh~
boycott_2.php~ leprechaun nikon_bash6.sh~ style.css
boycott_3.php links oakbash1.sh terminal
boycott_3.php~ Merrill_Jensen oakbash1.sh~ ticket
center1.css micah oakbash2.sh trollnsaday_2.php
center1.css~ migrate_ftp1.pl oakbash2.sh~
cleaning1.php music1.pl pacific
$ cd leprechaun/
$ ls -al
total 28
drwxr-xr-x 3 fred automation 4096 Sep 18 17:40 .
drwxr-xr-x 14 fred automation 4096 Sep 18 17:40 ..
-rw-r--r-- 1 fred automation 793 Sep 18 17:40 ident.txt
drwxr-xr-x 4 fred automation 4096 Sep 18 17:40 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 17:40 terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 17:40 terminal2.pl
-rw-r--r-- 1 fred automation 1379 Sep 18 17:40 terminal_4.html
$

Q1) How do I modify this copying so the highest number .pl becomes
leprechaun1.pl, that is the value of the new directory name, with 1.pl
post-placed?

I would expect the values at the invocation of the script to be the rhs
of this:

$ cp -rf terminal leprechaun

So one thinks of these as child directories where one populates the next.

One thing I don't want to do is force over-writing: I'd rather shit the
bed instead.

Q2) After the cp command or copy/paste

$ cp bash3.sh bash4.sh
$ ls -l
total 240
drwxr-xr-x 4 fred automation 4096 Sep 18 12:40 about
-rw-r--r-- 1 fred automation 565 Jun 3 16:44 about1.css
-rw-r--r-- 1 fred automation 645 Jun 3 16:43 about1.css~
-rw-r--r-- 1 fred automation 663 Jun 4 17:39 about2.css
-rw-r--r-- 1 fred automation 664 Jun 4 15:13 about2.css~
-rw-rw-r-- 1 fred automation 284 Jan 29 2013 bash3.sh
-rw-r--r-- 1 fred automation 284 Sep 18 18:02 bash4.sh

I'm not sure if I've given my system enough permissions or not, as I
know it's best practice to give it less.

Q2) Can I alter permissions for this directory such that a cp command
does not change permissions?

Beautiful day here in Oakland. Grass growing.
--
Cal

Cal Dershowitz

unread,
Sep 18, 2013, 10:50:17 PM9/18/13
to
Without reference to a file, this is lacking something, which I'm sure
you could fill in. Let's move on.

Ben,

You've helped me a lot with this template, and I want to thank you for
it. I believe you make the world better by helping my stupid little
situation.

The first issue is all the use's. Holy Christ I had to struggle to get
HTML::FromText, so let's chop it up.

#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use File::Basename;
use Cwd;
use HTML::FromText;
use Text::Template;
use File::Slurp;


first subroutine. get config.

## usage needs 1 arg from argv my_ftp
#identity and config
my $ident = 'ident.txt';
my ( $config, $domain );
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}
$domain = $config->{ $ARGV[0] };
die("unknown domain: $ARGV[0]") unless $domain;


second subroutine: establishing html connection and exchanging information
third subroutine: create html file


# create unicode html file
open( my $fh, ">:utf8", $html_file )
or die("Can't open $html_file for writing: $!");
my $input = "template_stuff/hc_input2.txt";
# write in the header
open( my $gh, "<:utf8", $input ) or die("Can't open: $!");
my $template2 = Text::Template->new(SOURCE => $input)
or die "Couldn't construct template: $Text::Template::ERROR";
my %vars = (
title => $word,
headline => 'Helpful Unix Commands',
place => 'Oakland',
css_file => 'rad1.css',
);
my $now_string = localtime;
$vars{date} = $now_string;
my $result = $template2->fill_in(HASH => \%vars);
if (defined $result) { print $fh $result }
else { die "Couldn't fill in template: $Text::Template::ERROR" };

This has to be relegated to file status. Since it is a template of a
rebus, I suggest I call it rebus1.tmpl .

#create template outside loop
my $template = <<'TEMPLATE';
<img src="http://www.merrillpjensen.com/images/%s"/>
%s
TEMPLATE

Captions are now files. In a child directory of the template itself.

#get captions
my $dir2 = "captions/";
my @files2 = <$dir2*>;
@files2 = sort @files2;
print "files are @files2\n";

yikes: adios ->

local $/ = undef;
my $string = read_file($files2[0]);
print "text is $string\n";
my $kludge = text2html(
$string,
urls => 1,
email => 1,
paras => 1,
);

print "text is $kludge\n";

$ftp->cwd("/images/${word2}/") or die "cwd failed $@\n";
# main control
for my $name (@files) {

# captions
my $caption = $kludge;
print "name is $name\n";
my $remote_file = basename($name);
print "remote is $remote_file\n";
$ftp->put( $name, $remote_file ) or die "put failed $!\n";
printf $fh $template, "${word2}/" . $remote_file, $caption;

}

subroutine to write in the footer

# write in the footer
my $footer = "template_stuff/footer_center.txt";
open( my $hh, "<:utf8", $footer )
or die("Can't open: $!");
while (<$hh>) {
print $fh $_;
}
close $fh;

subroutine to upload

$ftp->pwd();
$ftp->ls();
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cwd("/pages") or die "Cannot change working directory ",
$ftp->message;
$ftp->put($html_file) or die "put failed $@\n";

I don't have a specific question other than the ones I've asked elsethread.

Peace.
--
Cal



Ben Bacarisse

unread,
Sep 18, 2013, 11:47:27 PM9/18/13
to
Cal Dershowitz <c...@example.invalid> writes:
<snip>
> You've helped me a lot with this template,

Have you considered using one of the fine Perl template systems? If you
do, be sure to ask in a Perl group rather than a shell one
(comp.lang.perl.misc comes to mind).

<snip>
--
Ben.

Cal Dershowitz

unread,
Sep 19, 2013, 2:03:39 AM9/19/13
to
I've been through this spin cycle more than once, and I need to remark
that I don't think the commentary in c.l.p.misc is worth the asking.
--
Cal

Lew Pitcher

unread,
Sep 19, 2013, 12:40:16 PM9/19/13
to
On Wednesday 18 September 2013 21:17, in comp.unix.shell,
You don't "modify this copying", at least not as an argument to cp(1).
You will have to write a script to perform this action.


> I would expect the values at the invocation of the script to be the rhs
> of this:
>
> $ cp -rf terminal leprechaun
>
> So one thinks of these as child directories where one populates the next.
>
> One thing I don't want to do is force over-writing: I'd rather shit the
> bed instead.

Eat plenty of bran during the day, and take a laxative before retiring,
then. :-)

> Q2) After the cp command or copy/paste
>
> $ cp bash3.sh bash4.sh
> $ ls -l
> total 240
> drwxr-xr-x 4 fred automation 4096 Sep 18 12:40 about
> -rw-r--r-- 1 fred automation 565 Jun 3 16:44 about1.css
> -rw-r--r-- 1 fred automation 645 Jun 3 16:43 about1.css~
> -rw-r--r-- 1 fred automation 663 Jun 4 17:39 about2.css
> -rw-r--r-- 1 fred automation 664 Jun 4 15:13 about2.css~
> -rw-rw-r-- 1 fred automation 284 Jan 29 2013 bash3.sh
> -rw-r--r-- 1 fred automation 284 Sep 18 18:02 bash4.sh
>
> I'm not sure if I've given my system enough permissions or not, as I
> know it's best practice to give it less.
>
> Q2) Can I alter permissions for this directory such that a cp command
> does not change permissions?

The cp(1) command doesn't "change permissions", it simply copies data. Your
Unix vendor may have "extended" cp(1) with various options to manage file
metadata; Gnu, for instance, provides a --preserve= argument that permits
you to specify the metadata to be preserved (mode, ownership, timestanps,
context, links).

You may find that your umask has influenced the permissions given to the new
file. Remember, umask specifies the permission bits /that will
automatically be set to 0/.

And, to answer your question, no, you cannot alter the permissions for the
directory to cause cp(1) to use the input file's permissions when creating
the output file.
0 new messages