some basic questions about unix ..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers some basic questions about unix ..
# 1  
Old 01-29-2009
PHP some basic questions about unix ..

Hi all
today i gone through worst interview of my life that for hour questions were so basic but i never though about them now i am figuring out answers my self but i would appreciate if you ppl help me ... i am listing some of the questions i remember ..

1 )
Code:
$ cat a.sh
#! /usr/bin/ksh
echo "hello world"

$ bash a.sh

now which shell will execute this echo statement ?

2 ) how to call one shell script from other script without creating new process ? interviewer told me i want to use $aaa from a.sh script to b.sh without exporting it ?

ANSWER
Code:
$ cat a.sh
a=hello
export b=world
. b.sh

$ cat b.sh
echo "$a"
echo "$b"

$ ./a.sh
hello
world

$ cat a.sh # modified 
a=hello
export b=world
b.sh

$ ./a.sh

world
$


3 ) how to know current shell you are working in ?
echo $SHELL ...but he was looking for something else ..i dont know what exactly.
Code:
ps $$

sorry for not searching the forum before posting questions here is the thread : https://www.unix.com/unix-dummies-que...ent-shell.html

4 ) how to display all ENV varaibles without using env command ? from shell and then from perl ( perl i will figure out ..)
Code:
#! /usr/bin/perl
use Env ;
foreach $key (sort keys(%ENV)) {
      print "$key = $ENV{$key}\n";
   }

i knew this one i was not sure ..

5 ) in perl say i have statement
Code:
 chomp ( $a = `grep "abcd" a.txt` ) ;

will it assign STDOUT / STDERR / BOTH ? if not BOTH then how to get other one ?

ANSWER : it read both

Code:
$ cat a.pl
#! /usr/bin/perl

print STDOUT "THIS IS PRINTED ON STDOUT\n" ;
print STDERR "THIS IS PRINTED ON STDERR\n" ;
$
$ cat b.pl
#! /usr/bin/perl

chomp ( $a =`perl a.pl`) ;
print "$a\n" ;

$ perl a.pl > a.txt
THIS IS PRINTED ON STDERR

$ perl a.pl > a.txt 2>&1

$ perl b.pl
THIS IS PRINTED ON STDERR
THIS IS PRINTED ON STDOUT
$

6 ) in perl what can be maximum length of variable ? like my $a = "aaa...." how far can i go ?
@ corona688 - you are right ... looks like there is no limit
Code:
my $i = 0 ;
my $Char = a ;

while ( $i < 3000000 )
{
    $Var .= ${Char} ;
    $i++ ;
}

$count = length ($Var) ;
print "variable : [$Var]\n" ;
print "can print upto $count\n" ;

above script worked ...without any probs ..3 million is more than enough

7 ) in perl how can i execute a module ? and how can i use variable used in modul a in module b ?

ANSWER :

suppose i have module "A" and variable "aaa" inside it i want to access "$aaa" in B module then i would use something like
$bbb = $A::aaa ;

read it on perlmod man page ....

i can remember this much only right now ... if i find out i will put answers in this thread only ...

@ MOD : this is not homework. if this is against rules of forum you can delete this thread.

Last edited by zedex; 02-02-2009 at 02:31 PM.. Reason: answer for q 5
# 2  
Old 01-29-2009
Quote:
Originally Posted by zedex
Hi all
today i gone through worst interview of my life that for hour questions were so basic but i never though about them now i am figuring out answers my self but i would appreciate if you ppl help me ... i am listing some of the questions i remember ..

1 )
Code:
$ cat a.sh
#! /usr/bin/ksh
echo "hello world"

$ bash a.sh

now which shell will execute this echo statement ?
Korn shell - ksh


The rest of your questions I will leave to people with better knowledge...sounds like it was a tough interview.
# 3  
Old 01-29-2009
Quote:
Originally Posted by zedex
now which shell will execute this echo statement ?
Just work it out logically. What does bash do when you run 'bash filename'? How will it treat lines beginning with #?
Quote:
2 ) how to call one shell script from other script without creating new process ? interviewer told me i want to use $aaa from a.sh script to b.sh without exporting it ?
'source filename'.
Quote:
6 ) in perl what can be maximum length of variable ? like my $a = "aaa...." how far can i go ?
I don't think perl has a real limit.
# 4  
Old 01-29-2009
Quote:
2 ) how to call one shell script from other script without creating new process ? interviewer told me i want to use $aaa from a.sh script to b.sh without exporting it ?
Dont understand.. Is he thinking of exec ?

Quote:
4 ) how to display all ENV varaibles without using env command ? from shell and then from perl ( perl i will figure out ..)
Well in ksh I would type :
Code:
# set

# 5  
Old 01-29-2009
1. bash
2. use the dot command to invoke the script
3. ps -f
4. In ksh I would use "typeset -x". Also there is "printenv".

I'm not real good at perl, but I think....
5. stdout; 2>&1
6 and 7: I'll pass

When you say:
bash file
bash will open the file and start reading commands. No kernel exec happens and to any shell "#! /usr/bin/ksh" is just a comment.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

some basic unix questions pls iam a newbie

what is a assembler what isa interpreter what is a compiler what is a socket what is a port what is meant by listening to a port how we do it how to know version and standard of unix one is using when one is on public access unix account how to see a jobid in... (1 Reply)
Discussion started by: scimitar
1 Replies

2. UNIX for Dummies Questions & Answers

hp-ux basic questions

I have multiple questions How to list or find only Nov month's files? How can I get state of process like running, stop, or sleep etc? How can I check dependences of processes? plz ans any if u can thx regards, Mazhar Hussain (3 Replies)
Discussion started by: mazhar99
3 Replies

3. UNIX for Dummies Questions & Answers

Basic security questions

Hey guys, I've seen this posted a few times when i searched but I kinda want to know the cleanest way of doing it. On Solaris 8 and Solaris 9 What is the best way to disable telnet ssh1 and remote root login premanently? I've seen posts that say edit /etc/services edit this edit that... (3 Replies)
Discussion started by: kingdbag
3 Replies

4. Programming

Basic questions on writing a Unix Service (newbie help!)

Hi there. I've got 12 years experience writing C++ on Windows, and 3 years C# on Windows. Now my boss wants me to write a C++ app to run on Unix as a multithreaded 'service' (i.e. a program that runs with no user intervention). Some quick questions for The Experts: * Whats the best C++... (3 Replies)
Discussion started by: Rutland Gizz
3 Replies

5. UNIX for Dummies Questions & Answers

Some basic questions

Hi- Newbie here with some basic questions: 1) I can't get alias to work. I tried alias ll='ls -al', but it doesn't work. When just typing 'alias', the new definition doesn't appear. I'm in a bash shell -- is that the problem. I tried switching to csh, but that didn't seem to help. This... (5 Replies)
Discussion started by: Aworstell
5 Replies

6. UNIX for Dummies Questions & Answers

Basic Unix Questions

OK, here's a question from a true UNIX newb: How does one make a 20 line file? I'm lost. :confused: OK, I figured it out. :D (0 Replies)
Discussion started by: Kitchen Zinc
0 Replies

7. UNIX for Dummies Questions & Answers

Basic SFTP questions

I'm trying to find out what all is involved with setting up SFTP? 1) Do Solaris machines come with a SFTP server and client already installed. 2) If so would I have to install SFTP clients on windows, if I want to transfer files to a Solaris box? 3) If SFTP doesn't come prepackaged would I... (1 Reply)
Discussion started by: JohnRodey
1 Replies

8. UNIX for Dummies Questions & Answers

basic UNIX questions

Can somebody please tell me a little about UNIX OS. For instance, is it ideal for digital media or how easy is it to get help and support? (3 Replies)
Discussion started by: buk5d
3 Replies
Login or Register to Ask a Question