我尝试使用以下代码将小写字符串转换为大写并将其分配给变量
该脚本以 .tn 扩展名编写
set y a12
y_up=$( tr '[A-Z]' '[a-z]' <<< $y)
echo $y
echo $y_up
Run Code Online (Sandbox Code Playgroud)
但我收到错误
invalid command name "A-Z"
while executing
"A-Z"
invoked from within
"y_up=$( tr '[A-Z]' '[a-z]' <<< $y) "
Run Code Online (Sandbox Code Playgroud)
我该如何转换这个?
我想提示用户输入,在一段时间后,如果没有响应,脚本必须退出.我有这个代码
eval {
local $SIG{ALRM} = sub { die "timeout getting the input \n" };
alarm 5;
$answer = <STDIN>;
alarm 0;
chomp $answer;
};
if ($@) {
#die $@ if $@ ne "timeout getting the input\n";
$answer = 'A';
}
Run Code Online (Sandbox Code Playgroud)
警报超时正在按预期工作,但是我希望在倒计时后每秒减少一次额外的打印声明(比如10秒说"10 ... 9 .. 8 ..还有")任何人都可以请求如何获取此功能与超时一起嵌入.
谢谢
我有一个包含一些行的文件.我想将每一行存储到一个变量中,但必须在shell脚本中选择该行(在perl - chomp($ Line)中完成它的方式).
包含打开文件和读取行的功能的代码是
p_file() {
File=$1
count=0
while read LINE
do
chomped_line=$LINE **#How to delete the linebreaks**
echo $chomped_line
done < $File
}
Run Code Online (Sandbox Code Playgroud)
如何删除换行符并将字符串存储在变量(chomped_line)中,如上所示
我试图system("cd /home/user")在perl中实现一个bash命令,但是我得到一个错误说
Can't exec "cd": No such file or directory at temp.pl
Run Code Online (Sandbox Code Playgroud)
有没有办法将当前工作目录更改为指定的工作目录,并且在perl脚本退出后仍然存在更改.
我在C++中有两个类
Class A
{
public:
int v;
}
Class B
{
public :
void calculation ();
}
void B::calculation ()
{
int i;
for (i= 1; i < object_a.v ;i++)
{
//some body
}
}
//now I have created an object for class A and for that object I have
//got some value for "v"
int main ()
{
A object_a();
cout << "The value of variable v in class A is" << object_a.v << ;
}
Run Code Online (Sandbox Code Playgroud)
对于上面的示例代码,我尝试使用在类B中定义的另一个函数中使用object_a检索的变量.但是它会抛出未声明的错误.有人可以帮我这里怎么去吗?
PS:我在B类中编译函数"calculation()"时遇到错误