I want to read the content of a specific folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I want to read the content of a specific folder
# 1  
Old 08-21-2015
Cd ib Batch File not work

Why does not work a cd in a shell schript file.




How do you get to run it?

I use these code:

Code:
#!/bin/sh
cd workspace

array=($(ls -d */))
 echo ${array[@]}

But it doesn't change to workspace

Moderator's Comments:
Mod Comment editby bakunin: please user CODE-tags as required by the rules. Thank you.

Last edited by bakunin; 08-21-2015 at 07:44 AM..
# 2  
Old 08-21-2015
Please use code tags as required by forum rules!

Any error messages? workspace needs to be a directory below your current working dir. Please post your directory structure.
# 3  
Old 08-21-2015
Quote:
Originally Posted by Linuxmann
But it doesn't change to workspace
How wouldyou know that? If you do a pwd before and after you will see no change, because the script is started ina separate shell, which closes at the end of the script.

Put a pwd into the script and you will see the effect.

If you want to permanently change the currrent working directory you have to execute the script with a dot in front, like this:

Code:
. /path/to/script

This will tell the shell not to load a separate shell process and to execute the script there but to execute it in the current environment instead.

I hope this helps.

bakunin
# 4  
Old 08-21-2015
How combine pwd with my file?

These not work:

Code:
x=$(pwd)
a = "/workspace"
c =x + a
echo "The current working directory : $c"

---------- Post updated at 08:41 AM ---------- Previous update was at 07:35 AM ----------

Now i use these but it don't work also.

Code:
#!/bin/sh

a=$(pwd)
b=/workspace
c=/workspace


cd $a$b


array=($(ls -d */))
 echo ${array[@]}

# 5  
Old 08-21-2015
I want to read the content of a specific folder

I want to read the contents of a specific folder


I use these script, but i can not change to the correct file workspace




Code:
#!/bin/sh

array=($(ls -d /typo3cms/cms_****/fotouploadv2/Modul2/workspace))
 echo ${array[@]}

# 6  
Old 08-21-2015
What output are you getting from this. What output do you WANT but are not getting?
# 7  
Old 08-21-2015
Why open another thread for the very same content?

Original: Cd ib Batch File not work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux read specific content file from tar.gz files without extracting

hello i wish to write the result of these below conditions in a file: 1. in a specific folder, i have many tar.gz files. 2. each tar.gz file contains ".dat" file in sub folders. 3. i wish to get the full path of these .dat files, if i find in it a specific word ("ERROR24"). 4. all this... (6 Replies)
Discussion started by: jimmyjames9
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

How can i move folders and its content if folder is older than 1,5 days and keep subdirs in bash?

Hello all, do you know any way i can i move folders and its content if folder is older than 1,5 days in bash? I tried: find /home/xyz/DATA/* -type d -ctime +1.5 -exec mv "{}" /home/xyz/move_data_here/ \;All i got was that Files from DATA /home/xyz/DATA/* ended messed up in... (1 Reply)
Discussion started by: ZerO13
1 Replies

4. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

5. Shell Programming and Scripting

Delete all content in folder and not show any stderr/stdout

Hi i am a newbie, and have trying something that looked easy at first sight. in this script i want to delete all the files and directories in subdirectory1 (but not delete subdirectory1) and dont show any stderr or stdout messages: i try this but the stderr and stdout is shown...and it says... (2 Replies)
Discussion started by: bash100
2 Replies

6. Shell Programming and Scripting

Reading files under a folder and formatting content of each file

I have 'n' number of files in a folder .each file in the folder "myfolder" is having the content like. COLNAME ------------ AAAAAA BBBBBB CCCCCC DDDDDD ... ... ... ZZZZZZ 26 recrod(s) selected. My request is by reading each file in "myfolder" and format each file such a way... (18 Replies)
Discussion started by: rocking77
18 Replies

7. Shell Programming and Scripting

How to copy specific file.txt in specific folder?

hye there... i have a problem to copy file in specific folder that will change the name according to host,time(%m%s) and date(%Y%M%D) example folder name: host_20100531.154101801 this folder name will always change... but i just want to copy the AAA.txt and BBB.txt file.. really need... (17 Replies)
Discussion started by: annetote
17 Replies

8. UNIX for Dummies Questions & Answers

Zip recursive content of folder when (not current directory=

Hi, Is there a way to zip the content (recursively) of a folder other then the current directory, and keep the directory structure intact? Example: /var/tmp/myfolder ----------------- file1 ----------------- file2 ----------------- folder1 ------------------------ file3 Now I want... (3 Replies)
Discussion started by: jimih
3 Replies

9. Shell Programming and Scripting

Can I use read to read content of a variable

Can I use the read command to read the contents of a variable? I'm trying by using the following code and getting nothing back. I'm in a Linux environment. #!/bin/ksh IFS=~ VAR1=1~2~3~4 echo $VAR1 | read a b c d print "$a $b $c $d" (9 Replies)
Discussion started by: nmalencia
9 Replies

10. Shell Programming and Scripting

how to store the first content of the folder in a variable?(Urgent)

Hi All, I need urgent help. Because just now i have to give this code to my client. I have a folder name is Testing. this Testing folder contains the following 3 files. 1.txt 2.txt 2.txt Now I want to store the first value of my folder in a variable say suppose $a. Means i want that... (3 Replies)
Discussion started by: sunitachoudhury
3 Replies
Login or Register to Ask a Question