Sponsored Content
Top Forums Shell Programming and Scripting Change directory within a bash shell script Post 303028365 by HikingLife on Saturday 5th of January 2019 02:38:41 PM
Old 01-05-2019
Change directory within a bash shell script

Hi,

I have been trying to execute the below command by changing directory and then copying contents of one directory to another by doing some file name manipulations in between. However this isnt working since as soon as the statement completes it goes back to the original folder. Can someone help in telling me how to change a directory in a script so I can execute subsequent steps within it using and modifying a variable through the steps.

This works fine from command line, however gives bad substitution error from the script because of the issue explained above
Code:
for file in /ABC/DEF/*.done; do file="${file%.*}"; file="${file##*.}"; cp "${file:0:31}"*.* /ABC/EDG/; done

Basically check for all files with name like CAT_TURNAROUND_201811120_075221_3.done in the folder ABC/DEF/*.done, then get all the files starting with just this part CAT_TURNAROUND_201811120_075221from this directory/ABC/DEF/ copied to /ABC/EDG/

Will really appreciate a solution. I have been trying to figure this out and checked various forums and tried alias, function etc. But it isn't working.




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by HikingLife; 01-05-2019 at 10:03 PM.. Reason: Correcting typos and fixing the sample file name
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change of directory thru script

:confused: Hi All, This script is not working. I want to change the directory as per users selection in current shell. Looks like it is spawning sub-shell internally. I have used . changedir.sh source changedir.sh ./changedire.sh But did not work. Currently shell directory remain the... (4 Replies)
Discussion started by: shiningram
4 Replies

2. Shell Programming and Scripting

change directory using shell script

How do u change ur directory using a shell script?? (0 Replies)
Discussion started by: laxmi
0 Replies

3. Linux

Change directory in a shell script

How do u change ur directory using a shell script?? (12 Replies)
Discussion started by: laxmi
12 Replies

4. Shell Programming and Scripting

how to change shell from BASH to C

hi all, how can i change my shell from BASH to C shell? i am using cygwin. (3 Replies)
Discussion started by: npatwardhan
3 Replies

5. UNIX for Dummies Questions & Answers

Change the default shell from bash to ksh

Currently my default shell is bash.How can i change itto ksh... (2 Replies)
Discussion started by: dr46014
2 Replies

6. Shell Programming and Scripting

Automatically change to Bash shell after login

Hi men, I think this must be a very common job. "How could to Automatically change to Bash shell after login and then jail user can only using this shell". I want monitor user works.However it just only effect on Bash shell. Consequently if the user change the shell it will be worthless. ... (4 Replies)
Discussion started by: tien86
4 Replies

7. Shell Programming and Scripting

Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files. So, take the following file: /home/slag/www/webcam.jpg Rename it--preferably with a time stamp. Place it in say: /home/slag/www/history/ ... (4 Replies)
Discussion started by: robfindlay
4 Replies

8. Shell Programming and Scripting

directory change in shell script

Hi, I am trying to change the directory in my script, & want to check if the directory is present or not . Ex: cd /home/xyz/temp/logs if the logs directory is not present i want to show the error in script instead of shell script error. Can anybody please help me on the same Thx in... (2 Replies)
Discussion started by: vls1210
2 Replies

9. Shell Programming and Scripting

How to change a directory in shell script?

HI, I need to change the working directory by using the shell script /Export/home/user_name I have to go one step back like /Export/home Please help on this.:confused: (3 Replies)
Discussion started by: thelakbe
3 Replies

10. Shell Programming and Scripting

Change directory shell

#!/bin/bash echo -n "Enter number of sanger patients : "; read id perl -ne 'chomp; system ("perl table_annovar.pl $_ humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo")' < file.txt I have the above script... (7 Replies)
Discussion started by: cmccabe
7 Replies
FS_WHICHCELL(1) 					       AFS Command Reference						   FS_WHICHCELL(1)

NAME
fs_whichcell - Returns the cell to which a file or directory belongs SYNOPSIS
fs whichcell [-path <dir/file path>+] [-help] fs whi [-p <dir/file path>+] [-h] DESCRIPTION
The fs whichcell command returns the name of the cell in which the volume that houses each indicated directory or file resides. To display the file server machine on which the volume housing a directory or file resides, use the fs whichcell command. To display the cell membership of the local machine, use the fs wscell command. OPTIONS
-path Idir/file path>+ Names each AFS file or directory for which to return the cell membership. Partial pathnames are interpreted relative to the current working directory, which is also the default value if this argument is omitted. -help Prints the online help for this command. All other valid options are ignored. OUTPUT
The output includes a line for each directory or file, naming the cell to which the volume that houses the directory or file resides. EXAMPLES
The following example shows that the current working directory resides in a volume in the ABC Corporation cell: % fs whichcell File . lives in cell 'abc.com' PRIVILEGE REQUIRED
None SEE ALSO
fs_wscell(1), fs_whereis(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FS_WHICHCELL(1)
All times are GMT -4. The time now is 04:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy