Look-back pwd until expression found on Linux [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Possible folder layouts:
path/to/a/project1/FOO-****/some/where/inside
path/to/another/project2/FOO-****/some/where/else/inside
I am looking for single line bash command that can drop me into a location FOO-**** which can be in any form, FOO-source, FOO-system-test or FOO-unit-test or any similarly named folder, while my pwd could be anywhere inside that.

What about something like this, searching backwards for a FOO* directory :
while [[ $PWD != / ]]; do [[ `basename "$PWD"` != "FOO"* ]] && cd .. || break ; done

Related

Linux script with cd and read [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
Is there any way I can integrate cd command with read?
read -p "location" loc
cd /home/dir/$loc
Yes, you can; it's not pretty, but it works. :)
cd /home/dir/$( read -p "location" loc; echo $loc)
It's also a bit costly as it invokes a sub-shell.

Use echo to create a bash fils [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I wanted to make a one-liner that would create an executable. It's for a quick guide I' making for a friend, so that it would be an easy copy-paste job.
I have this:
export FILE=spotify; [ -f ~/.local/bin/$FILE ] && echo "File $FILE already exists. Couldn't create it..."; [ -f ~/.local/bin/$FILE ] || { echo $"#!/bin/sh\nflatpak run com.spotify.Client" > ~/.local/bin/$FILE; chmod +x ~/.local/bin/$FILE; echo "Successfully created $FILE" }
However I am stuck on echo "#!/bash/sh" which causes "event not found"...
Any ideas how to overcome that?
In a Bash interactive shell the exclamation mark is used for searching the Bash history. Specifically, it replaces the string after the exclamation mark with the first entry in the history which matches that string. If there is no such entry, you get the symptom you're seeing.
The solution is to use a single-quoted string.

Path to Files on server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to use git for my sites. So I understand that I have to use SSH and initialize git in the folder. But I can't find those files and want to know what is the path for those files?
something I found, If you have PHP then you can use this to get absolute path
<?php
$path = getcwd();
echo "This Is Your Absolute Path: ";
echo $path;
?>
example :- /home/user/public_html/test/test.php.
refrence :- Check this

Shell script to compare file names(without extension) in a directory [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
My requirement is I will have xml and pdf files like pairs.(e.g.,file1.xml, file1.pdf and file2.xml,file2.pdf) in same folder.
I need to check for xml files which are not having pdf pair and move them to different folder.(e.g., if file3.xml doesn't have file3.pdf, I need to move it to different folder).
Please answer me the shell script to do get this functionality done.
You can remove the extension using parameter expansion:
#! /bin/bash
for file in *.xml ; do
if [[ ! -f ${file%.xml}.pdf ]] ; then
mv "$file" folder/
fi
done

How to write file creation script? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am very new to scripting and would like to know how to write a script fileCreate which has two optional parameters two input arguments as shown below:
fileCreate <filename> <path>
<filename> parameter signifies the name of the file in which the
contents will be saved
<path> parameter signifies the directory structure where the file will
be saved.
When the program is executed it will open an editor and user can input any contents, that will be saved as specified.
If no parameters are passed, the default is current directory and userfileX (userfileX to the number of times the file is created)
If there already exists a file of similar name and having same contents then the user should be able to append the file or else just the date gets modified.
Using vi as the editor:
D=${2:-.}
F=$1
if [ -z "$F" ] ; then
X=1
F="userfile$X"
while [ -f "$F" ] ; do
X=$(($X+1))
F="userfile$X"
done
fi
vi "$D/$F"

Resources