I am late into this thread, but why not walk before you can run...
As we have no idea what is in chxdir.sh nor the complete script that calls it we have to make wild guesses...
This is one way to get to change a directory on the fly from one script into another...
This is the script to be sourced, I have used the statement "source" instead of its shortcut "."...
The only proviso is you need to intitally know where both scripts are...
This is the master script...
Results of the experiment using OSX 10.14.1, default bash terminal...
Note I have initiated "NEWDIR" on both, not necessary but useful to keep track of used variables...
Now you know that it is possible transfer 'paths' give us your two scripts so that we can peruse them properly, unless you have some ultra-secret code you don't want making public.
Last edited by wisecracker; 01-09-2019 at 09:00 AM..
Hi,
I look for a script to create 150 directories :
d000
d001
d002
...
...
d149
would you help me please ?
I think it would be
for i
mkdir d$i
Many thanks.
PS :
#uname -a
AIX fserver 3 5 0050691A4C00 (2 Replies)
Is there ant way to increase max number of folders in the directory from the 32766:
Problem UFS:
shell>mkdir mmm
mkdir: mmm: Too many links
But there are no links, just folders.
shell>ls | wc -l
32766 (3 Replies)
I am having a problem getting this to work right. The script needs to search through directories and subdirectories. If a jpg is found then create a folder in that directory, so on and so forth. Here is what I have so far but it doesn't work right. Help please
#!/bin/bash
for d in `find ./... (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Do the procedure, which if there are 5 parameters then it creates 4 directories with names of 4 parameters, in... (2 Replies)
Hello,
I'm pretty new to scripting and trying to do a simple (well, I thought so) administrator task. I'm using bash.
I want to create 10 directories under the one directory and apply permissions at the same time.
I've worked out the make directories part: mkdir /userdata/folder{1..50}... (7 Replies)
Howdy,
Puttering around in unix, and read this in the mkdir man page:
"The mkdir utility creates the directories named as operands..."
What does this mean, i.e. as operands?
Many thanks,
DN (2 Replies)
Hello, :)
I've an issue with the creation of a directory, All work without it :mad: So, below, my scripts with the debug output :
#!/bin/bash
# PATHS
HOME_BACKUP="/home/backup"
HOME_SCRIPT="/home/scripts/test/backup_server"
TARGET="/var/www"
# DATE
DATE_Ymd=$(date +%Y-%m-%d)
#... (1 Reply)
hi linux expert
what is a difference between:
mkdir test and mkdir ./test
and also
if ( -e /test ) then and if ( -e ./test ) then
thanks in advance
Please use icode or code tags next time for your code and data (1 Reply)
I have a file with lines like:
111 12 7
111 13 8
112 12 9
115 31 3
120 31 9
123 10 7
125 12
I want to make a script which, split the first column into parts (101-110, 111-120...), and make directories for its part with name (101-110, 111-120...) Also i want in every directory include... (7 Replies)
Discussion started by: efsarantis
7 Replies
LEARN ABOUT SUSE
shell
Shell(3pm) Perl Programmers Reference Guide Shell(3pm)NAME
Shell - run shell commands transparently within perl
SYNOPSIS
use Shell qw(cat ps cp);
$passwd = cat('</etc/passwd');
@pslines = ps('-ww'),
cp("/etc/passwd", "/tmp/passwd");
# object oriented
my $sh = Shell->new;
print $sh->ls('-l');
DESCRIPTION
Caveats
This package is included as a show case, illustrating a few Perl features. It shouldn't be used for production programs. Although it does
provide a simple interface for obtaining the standard output of arbitrary commands, there may be better ways of achieving what you need.
Running shell commands while obtaining standard output can be done with the "qx/STRING/" operator, or by calling "open" with a filename
expression that ends with "|", giving you the option to process one line at a time. If you don't need to process standard output at all,
you might use "system" (in preference of doing a print with the collected standard output).
Since Shell.pm and all of the aforementioned techniques use your system's shell to call some local command, none of them is portable across
different systems. Note, however, that there are several built in functions and library packages providing portable implementations of
functions operating on files, such as: "glob", "link" and "unlink", "mkdir" and "rmdir", "rename", "File::Compare", "File::Copy",
"File::Find" etc.
Using Shell.pm while importing "foo" creates a subroutine "foo" in the namespace of the importing package. Calling "foo" with arguments
"arg1", "arg2",... results in a shell command "foo arg1 arg2...", where the function name and the arguments are joined with a blank. (See
the subsection on Escaping magic characters.) Since the result is essentially a command line to be passed to the shell, your notion of
arguments to the Perl function is not necessarily identical to what the shell treats as a command line token, to be passed as an individual
argument to the program. Furthermore, note that this implies that "foo" is callable by file name only, which frequently depends on the
setting of the program's environment.
Creating a Shell object gives you the opportunity to call any command in the usual OO notation without requiring you to announce it in the
"use Shell" statement. Don't assume any additional semantics being associated with a Shell object: in no way is it similar to a shell
process with its environment or current working directory or any other setting.
Escaping Magic Characters
It is, in general, impossible to take care of quoting the shell's magic characters. For some obscure reason, however, Shell.pm quotes
apostrophes ("'") and backslashes ("") on UNIX, and spaces and quotes (""") on Windows.
Configuration
If you set $Shell::capture_stderr to 1, the module will attempt to capture the standard error output of the process as well. This is done
by adding "2>&1" to the command line, so don't try this on a system not supporting this redirection.
Setting $Shell::capture_stderr to -1 will send standard error to the bit bucket (i.e., the equivalent of adding "2>/dev/null" to the
command line). The same caveat regarding redirection applies.
If you set $Shell::raw to true no quoting whatsoever is done.
BUGS
Quoting should be off by default.
It isn't possible to call shell built in commands, but it can be done by using a workaround, e.g. shell( '-c', 'set' ).
Capturing standard error does not work on some systems (e.g. VMS).
AUTHOR
Date: Thu, 22 Sep 94 16:18:16 -0700
Message-Id: <9409222318.AA17072@scalpel.netlabs.com>
To: perl5-porters@isu.edu
From: Larry Wall <lwall@scalpel.netlabs.com>
Subject: a new module I just wrote
Here's one that'll whack your mind a little out.
#!/usr/bin/perl
use Shell;
$foo = echo("howdy", "<funny>", "world");
print $foo;
$passwd = cat("</etc/passwd");
print $passwd;
sub ps;
print ps -ww;
cp("/etc/passwd", "/etc/passwd.orig");
That's maybe too gonzo. It actually exports an AUTOLOAD to the current package (and uncovered a bug in Beta 3, by the way). Maybe the
usual usage should be
use Shell qw(echo cat ps cp);
Larry Wall
Changes by Jenda@Krynicky.cz and Dave Cottle <d.cottle@csc.canterbury.ac.nz>.
Changes for OO syntax and bug fixes by Casey West <casey@geeknest.com>.
$Shell::raw and pod rewrite by Wolfgang Laun.
Rewritten to use closures rather than "eval "string"" by Adriano Ferreira.
perl v5.12.1 2010-05-13 Shell(3pm)