D
D
darzet2011-05-09 15:36:04
linux
darzet, 2011-05-09 15:36:04

Help a newbie with bash?

For me, this is new =)
I'm sitting poking around.
Help whoever can =)
Task1.
Given: a list of directories to search for and a file template. Find all files matching the pattern in all directories from the list.
This I did with find and grep
Task2.
Write a script that displays the name of the current user if this script is run without parameters, or the value of an environment variable received as a parameter, if such an environment variable exists.
user $USER ?
task3.
Write a script that takes the name of a process as a parameter and displays a list of the names of computers on which this process is running.
I do it with ps -A -o comm -o -user, but I don’t understand how to sort by process.
task4.
The script receives as parameters the names of two files with the same number of lines - file1 and file2. Merge these files into a file named file12 (or whatever it is if the third parameter is given) so that each nth line of file12 is the concatenation of the nth line from file1 and the nth line from file2
Merge with cat it turns out, but how line by line I don’t know yet =)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
DevMan, 2011-05-09
@darzet

task4.

paste -d\\0 file1 file2 > file12
I tested on Mac OS, maybe on Linux the result will be different, so
man paste
to help.

I
intr, 2011-05-10
@intr

The first is solved by one find(1), why grep(1)?
find /first_dir /second /third -name="*pattern*"

M
mark_ablov, 2011-05-09
@mark_ablov

Task 1:
#!/bin/bash
if [ $# = 0 ] ; then
echo $USER
else
printenv $1
fi

E
equand, 2011-05-12
@equand

Task 3 not
ps -A -o comm -o user | grep $proc | sort -u
?

D
darzet, 2011-05-09
@darzet

During an internship at a company, you need to learn the basics of Unix bash.
You will need to search by files and by text (in my case), but the tests are common to all.
And those who will write scripts for autotests and for those who will do it will be completely different =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question