transferring files between directories - bash

I have a directory called mdamb231(data_and_results) on the server and I want to transfer some files from this directory to another one, but since the name is weird it gives this error:
"-bash: syntax error near unexpected token `('".
I tried to change the name using mv command but got the same error.
do you guys know how to transfer my files from this directory?

You need to put backslashes before the brackets to escape them, i.e.
mv mdamb231\(data_and_results\) newfilename
or put the file path in single quotes
mv 'mdamb231(data_and_results)' newfilename

Related

How can you get the workspace if there is a space in the folder in jenkins declarative pipeline ]?

I am still pretty new to jenkins, and I was working on a pipeline and the workspace path goes as follows:
workspace/folder withspace/Pipeline. I am trying to give jenkins permissions to run a bash script, but because of the space in the folder name I get the error:
chmod: cannot access /workspace/folder’: No such file or directory
chmod: cannot access ‘withspace/Pipeline’: No such file or directory.
I realize that getting rid of the space in the folder name would fix the problem, but I was asked to fix this problem without removing the space. Here are the lines in my code causing the error Thank you for any suggestion and help!
In Bash you can either use quotation marks to enclose the entire path, or use a backslash to escape each space character.
In your case because you don't control the value, you need to quote the workspace path:
sh "chmod +x -R \"${env.WORKSPACE}\""

Why script delete file even with message rm: cannot remove '/path/file.txt': No such file or directory?

I made a bash script that delete files into a folder through a loop. The shell give me the error
rm: cannot remove '/path/file.txt': No such file or directory but the script remove the files correctly. So what could produce this error?
If the script is deleting the file but printing that error-message, then it's presumably trying to delete the file twice — either there's a duplicate command, or there's a duplicate argument to the rm command. The first time works, the second time prints the error-message.

rsync with iCloud folders

I'm trying to set up a workflow to copy my iCloud script projects to my user library. Sadly apple decided to add quite a few unfriendly characters in the file path.
rsync -aE –delete ~/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/Script\ Libraries/ ~/Library/Script\ Libraries/
I keep getting. The following error:
rsync: link_stat "/Users/{{my_username}}/\#342\#200\#223delete" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-54/rsync/main.c(996) [sender=2.6.9]
The file is truncated so I feel it's a parse error, but I can't get it to work. I've tried a few different ways of writing the path, but they all are saying the path does not exist.
TL;DR: Your delete option is wrong. It should be --delete with 2 ASCII "minus" characters.
I suspect you may have a character encoding problem. Rich text editors and word processors often combine -- to an "emdash" character. The error message shows it is trying to access a file with some non-ASCII characters followed by "delete". This shows that rsync is treating the delete part as a file path instead of a command flag.

Using functions as an argument in Bash

I want to move a couple of files from point a to point b
but I have to manually specify
mv /full/path/from/a /full/path/to/b
but some times there are 20 files which I have to move manually. Instead of /full/path/form/a, can't I just enter the a function which returns all the files which I want to move in my case;
/full/path/to/b is a directory, it's the target directory which all the files with extenstions mp3, exe and mp4 must go to:
mv ls *.{mp3,exe,mp4} /full/path/to/b
If I have to move a couple of files and I don't want to do it one by one, how can I optimize the problem?
The command mv ls *.{mp3,exe,mp4} /full/path/to/b in your question is not correct.
As pointed out in comments by #janos, the correct command is
mv *.{mp3,exe,mp4} /full/path/to/b
mv can complain about missing file if the file is really missing and/or the path is not accessible or is not valid.
As i can understand by your question description, if you go manually to the source path you can move the file to the desired directory.
Thus it seems that path is valid, and file exists.
In order mv to keeps complaining about *.mp3 not found (having a valid path and file) the only reason that pops up in my head is the Bash Pathname Expansion feature (enabled by default in my Debian).
Maybe for some reason this pathname expansion bash feature is disabled in your machine.
Try to enable this feature using command bellow and provide the correct command to mv and you should be fine.
$ set +f
PS: Check man bash about pathname expansion.

Logrotate lastaction script not working

I have a lastaction script I'm trying to run in my "log" folder, as I want to move all files and folders in the log folder inside the log/archive folder. So I simply added
mv log/* log/archive/2014
Obviously enough, I get an error saying archive folder cannot be moved to a subdirectory of itself, so I tried adding the extra parameter to the move command to move everything except the archive folder.
mv !(archive) log/* log/archive/2014
This exact command, if executed from cli, works just fine, but when added inside the lastaction/endscript block, it throws the following message
logrotate_script: 2: logrotate_script: Syntax error: "(" unexpected
Anybody has any clue on why this happens?
You are using bash as your shell. You also have the extglob setting enabled.
When logrotate is executing that shell script one or the other of those is not true.
Also that mv command looks odd to me. If archive is under log then I don't see why !(archive) doesn't have log/ as a prefix. Also the log/* should still be matching log/archive regardless of the extglob glob before it. (That is I would think you wanted mv log/!(archive) log/archive/2014, assuming you don't feel like just ignoring the warning from mv in the first place.)

Resources